Posts

Showing posts with the label Docker

Change Directory Command In Docker?

Answer : To change into another directory use WORKDIR. All the RUN, CMD and ENTRYPOINT commands after WORKDIR will be executed from that directory. RUN git clone XYZ WORKDIR "/XYZ" RUN make You can run a script, or a more complex parameter to the RUN. Here is an example from a Dockerfile I've downloaded to look at previously: RUN cd /opt && unzip treeio.zip && mv treeio-master treeio && \ rm -f treeio.zip && cd treeio && pip install -r requirements.pip Because of the use of '&&', it will only get to the final 'pip install' command if all the previous commands have succeeded. In fact, since every RUN creates a new commit & (currently) an AUFS layer, if you have too many commands in the Dockerfile, you will use up the limits, so merging the RUNs (when the file is stable) can be a very useful thing to do. RUN git clone http://username:password@url/example.git WORKDIR /folder RUN make

Can't Run Curl Command Inside My Docker Container

Answer : curl: command not found is a big hint, you have to install it with : apt-get update; apt-get install curl Ran into this same issue while using the CURL command inside my Dockerfile. As Gilles pointed out, we have to install curl first. These are the commands to be added in the 'Dockerfile'. FROM ubuntu:16.04 # Install prerequisites RUN apt-get update && apt-get install -y \ curl CMD /bin/bash So I added curl AFTER my docker container was running. (This was for debugging the container...I did not need a permanent addition) I ran my image docker run -d -p 8899:8080 my-image:latest (the above makes my "app" available on my machine on port 8899) (not important to this question) Then I listed and created terminal into the running container. docker ps docker exec -it my-container-id-here /bin/sh If the exec command above does not work, check this SOF article: Error: Cannot Start Container: stat /bin/sh: no such file or directory...

Cannot Execute RUN Mkdir In A Dockerfile

Answer : The problem is that /var/www doesn't exist either, and mkdir isn't recursive by default -- it expects the immediate parent directory to exist. Use: mkdir -p /var/www/app ...or install a package that creates a /var/www prior to reaching this point in your Dockerfile. When creating subdirectories hanging off from a non-existing parent directory(s) you must pass the -p flag to mkdir ... Please update your Dockerfile with RUN mkdir -p ... I tested this and it's correct. You can also simply use WORKDIR /var/www/app It will automatically create the folders if they don't exist. Then switch back to the directory you need to be in.

Access Host's Ssh Tunnel From Docker Container

Answer : Using your hosts network as network for your containers via --net=host or in docker-compose via network_mode: host is one option but this has the unwanted side effect that (a) you now expose the container ports in your host system and (b) that you cannot connect to those containers anymore that are not mapped to your host network. In your case, a quick and cleaner solution would be to make your ssh tunnel "available" to your docker containers (e.g. by binding ssh to the docker0 bridge) instead of exposing your docker containers in your host environment (as suggested in the accepted answer). Setting up the tunnel: For this to work, retrieve the ip your docker0 bridge is using via: ifconfig you will see something like this: docker0 Link encap:Ethernet HWaddr 03:41:4a:26:b7:31 inet addr:172.17.0.1 Bcast:172.17.255.255 Mask:255.255.0.0 Now you need to tell ssh to bind to this ip to listen for traffic directed towards port 9000 via ssh -L 1...

Building Dockerfile Fails When Touching A File After A Mkdir

Image
Answer : Looking at https://registry.hub.docker.com/u/library/jenkins/, it seems that /var/jenkins_home is a volume. You can only create files there while the container is running, presumably with a volume mapping like docker run ... -v /your/jenkins/home:/var/jenkins_home ... The docker build process knows nothing about shared volumes. This is currently investigated in docker/docker/issues/3639, and summarized in this comment: Okay, I did little research and it seems that volume is non-mutable between Dockerfile instruction . Here even smaller Dockerfile for testing: FROM busybox RUN mkdir /tmp/volume RUN echo "hello" > /tmp/volume/hello VOLUME ["/tmp/volume/"] RUN [[ -f /tmp/volume/hello ]] RUN rm /tmp/volume/hello RUN [[ ! -e /tmp/volume/hello ]] On each instruction we create new volume and copy content from original volume . Update April 2019: Use DOCKER_BUILDKIT=1 The new builder does not exhibit this behavior. Example...

Can Not Connect To Sql Server From Docker Supported Asp.net Core Project

Answer : This took me some time to work out, there are a number of small issues that may be wrong, which makes it frustrating. This can get even more frustrating as the .net core web application visual studio 2017 project that gets auto-generated doesn't work straight out of the box. Having this experience as your first exposure to Docker isn't ideal. I initially also had the incorrect assumption that the docker image would come with SQL Server inside the container, this is not the case, it's trying to access the database server that must be pre-installed on the host machine. Steps to follow (tested for a windows docker image, rather than linux); 1) Get the IP address of your host machine, by running a command prompt and typing IPCONFIG 2) Set the database connection string within you appsettings.json file to this Ip address, followed by the SQL Server port number, i.e.; 192.168.X.X,1433 3) Set the connection string not to use Trusted_Connection (delete thi...

Cannot Connect To The Docker Daemon On MacOS

Answer : On a supported Mac, run: brew install --cask docker Then launch the Docker app. Click next. It will ask for privileged access. Confirm. A whale icon should appear in the top bar. Click it and wait for "Docker is running" to appear. You should be able to run docker commands now: docker ps Because docker is a system-level package, you cannot install it using brew install , and must use --cask instead. Note: This solution only works for Macs whose CPUs support virtualization, which may not include old Macs. On macOS the docker binary is only a client and you cannot use it to run the docker daemon, because Docker daemon uses Linux-specific kernel features, therefore you can’t run Docker natively in OS X. So you have to install docker-machine in order to create VM and attach to it. Install docker-machine on macOS If you don't have docker-machine command yet, install it by using one of the following methods: Using Brew command: brew install dock...