Posts

Showing posts with the label Docker

Copy Multiple Local Files To Docker Container

Answer : There is a proposal for docker cp to support wildcards (7710), but it is not implemented yet. So that leaves you with bash scripting, using docker cp for each file: for f in data/*txt; do docker cp $f sandbox_web_1:/usr/src/app/data/; done The following command should copy whole directory data with its content of a data directory to your desired destination: docker cp data/ sandbox_web_1:/usr/src/app/ Tested on Docker version 1.12.1, but I haven't found any changes to a cp command in a the release 1.12.1 I am on Docker version 18.09 and found that I was able to copy all the files from my current local directory to the container's root by running: docker cp ./ image_name:

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...

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.

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...

Create Django Super User In A Docker Container Without Inputting Password

Answer : Get the container ID and run the command. docker exec -it container_id python manage.py createsuperuser I recommend adding a new management command that will automatically create a superuser if no Users exist. See small example I created at https://github.com/dkarchmer/aws-eb-docker-django. In particular, see how I have a python manage.py initadmin which runs: class Command(BaseCommand): def handle(self, *args, **options): if Account.objects.count() == 0: for user in settings.ADMINS: username = user[0].replace(' ', '') email = user[1] password = 'admin' print('Creating account for %s (%s)' % (username, email)) admin = Account.objects.create_superuser(email=email, username=username, password=password) admin.is_active = True admin.is_admin = True admin.save() else: print(...

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...

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'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...

COPY With Docker But With Exclusion

Answer : Create file .dockerignore in your docker build context directory (so in this case, most likely a directory that is a parent to node_modules) with one line in it: **/node_modules although you probably just want: node_modules Info about dockerignore: https://docs.docker.com/engine/reference/builder/#dockerignore-file For those who can't use a .dockerignore file (e.g. if you need the file in one COPY but not another): Yes, but you need multiple COPY instructions. Specifically, you need a COPY for each letter in the filename you wish to exclude. COPY [^n]* # All files that don't start with 'n' COPY n[^o]* # All files that start with 'n', but not 'no' COPY no[^d]* # All files that start with 'no', but not 'nod' Continuing until you have the full file name, or just the prefix you're reasonably sure won't have any other files. In my case, my Dockerfile contained an installation step, which produced the vendor director...

Connect Robomongo To MongoDB Docker Container

Answer : There is another way. You can SSH with Robomongo into your actual virtual server that hosts your docker applications (SSH tab, check "Use SSH tunnel" and complete the other fields accordingly) Now ssh into the same machine in your terminal. docker ps should show you your MongoDB container. docker inspect <mongo container id> will print out complete information about that container. Look for IPAddress in the end, that will give you the local IP of the container. In the "Connection" tab in Robomongo use that container IP to connect. Another sidenote: Make sure that you don't expose your mongodb service ports in any way (neither Dockerfile nor docker-compose.yml), cause that will make your database openly accessible from everywhere. Assuming that you don't have set up a username / password for that service you will be scanned and hacked soon. The easiest way is to enable forwarding the Mongo Container itself, here's how my docker-compo...

Context Or Workdir For Docker-compose

Answer : I think you're looking for working_dir . Search for "working_dir" in the docker-compose reference. You can specify the working directory as follows. version: '2' services: test: build: context: ./dir working_dir: /dir The build configuration in Docker Compose just ends up in a call to docker build , so you need to have a Dockerfile to use that workflow. As the docs for python:onbuild say, you can start with a minimal Dockerfile that just contains FROM python:onbuild . But as they also say, :onbuild isn't a great option, you'll have much more control building your own Dockerfile FROM python .