docker cp remotely (from container to host) - docker

I'm attempting to create a Jenkins job that remotely runs "docker cp" to copy a folder from the running container to the host machine.
Currently I have
docker run --rm docker:1.7.1 docker -H stuff.dev.blah.com:5000 cp cc_head:/opt/blah/build/cc_head/games /home/devadmin/games
But that doesn't work..
So, the machine host is stuff.dev.blah.com, and I can ssh to it with ssh devadmin#stuff.dev.blah.com
and at the host machine docker cp cc_head:/opt/blah/build/cc_head/games /home/devadmin/games works
All we can have here is docker 1.7.1, but if you manage to do this with a newer version I'd also be happy
the running container is called cc_head
Any suggestions?

You have two options
Mount the folder in cc_head container
Where you run the container cc_head and add -v /home/devadmin/games:/somefolder while running the same
docker run --rm docker:1.7.1 docker -H stuff.dev.blah.com:5000 cp cc_head:/opt/blah/build/cc_head/games cc_head:/somefolder
Mount the folder in separate container
Run another container on the host and map the /home/devadmin/games and use that for the copy operation
docker run --rm docker:1.7.1 docker -H stuff.dev.blah.com:5000 cp cc_head:/opt/blah/build/cc_head/games container:/somefolder

Related

How to run a python file which is present outside the docker container

Inside VM I created a docker container, Now there are some python files present outside the container(present in host directory of VM) how can I execute these python files from container anyone help me with this
You should mount the vm directory like this:
docker run -d -it --name your-container-name -v /host/path:/usr/local/bin container:image
Also you must be sure /host/path permissions are propperly set.
Volumes in docker
you can copy or mount the python file inside the docker container then execute the python with CMD.
For ex:
docker run -it -v myfile.py:/tmp/myfile.py python python /tmp/myfile.py
docker run -t -i -v <host_dir>:<container_dir> ubuntu /bin/bash
By this command I'm able to access host directory by inside the container where the directories are mounted and can able to run python file present in host by container

Running docker within docker missing file - docker run -v /var/jenkins_home/job:/build ./script.sh

I have Jenkins running in docker container. In Jenkins container we also run docker commands from pipelines. The problem with it is that when we run this from pipeline:
docker run -v /var/jenkins_home/job:/build ./script.sh
It does not mount the content of /var/jenkins_home/job
So I tested it with:
docker run -v /tmp:/build ./script.sh
And it mounted /tmp of the host machine not of Jenkins docker.
What causes this behaviour and how can I mount the path of Jenkins docker not host machine? OR is there anyway to make docker interpret /var/jenkins_home/job to host folder automatically?

how to copy files from one docker service to another, inside of docker bash

I am trying to copy a file from one docker-compose service to another while in the service's bash environment, but I cannot seem to figure out how to do it.
Can anybody provide me with an idea?
Here is the command I am attempting to run:
(docker cp ../db_backups/latest.sqlc pgadmin_1:/var/lib/pgadmin/storage/mine/)
The error is simply:
bash: docker: command not found
There's no way to do that by default. There are a few things you could do to enable that behavior.
The easiest solution is just to run docker cp on the host (docker cp from the first container to the host, then docker cp from the host to the second container).
If it all has to be done inside the container, the next easiest solution is probably to use a shared volume:
docker run -v shared:/shared --name containerA ...
docker run -v shared:/shared --name containerB ...
Then in containerA you can cp ../db_backups/latest.sqlc /shared, and in containerB you can cp /shared/latest.sqlc /var/lib/pgadmin/storage/mine.
This is a nice solution because it doesn't require installing anything inside the container.
Alternately, you could:
Install the docker CLI inside each container, and mount the Docker socket inside each container. This would let you run your docker cp command, but it gives anything inside the container complete control of your host (because access to docker == root access).
Run sshd in the target container, set up the necessary keys, and then use scp to copy things from the first container to the second container.

How can I make Docker Images / Volumes (Flask, Python) accessible for my host machine (macOS)?

I am running the latest macOS (Sierra) with Docker and Kitematic installed. I am also using Virtualbox for emulation.
I want to use the uwsgi-nginx-flask image but I have no idea how I can make the python files and the nginx directory inside my container accessible from outside the virtual machine ?
Haven't found anything about that on the website either.
Folders between the host and containers can be mapped and mounted by using the -v tag during runtime.
$ docker run -it -v /host/directory:/container/directory imagename:tag
You can alternatively use docker cp to copy stuff inside and outside of the container. For example
$ docker cp /path/to/file ContainerName:/path/inside/container
or
$ docker cp ContainerName:/path/inside/container/file .
you can mount the host directory to docker container which will be shared between host and docker
docker run --name container_image -d -v ~/host_dir:/container_dir docker_image

How to inspect a running Docker container

I've started a Docker container with tutum/lamp image with this command:
docker run -d -P --name design_patterns -v /public_html:/app tutum/lamp
As you can see, I mounted my local folder /public_html to /app directory in the container.
Having started this container, I realized that PHP files that are present in /public_html are not accessible from the browser. I should have probably mounted my local folder to a different location in the container.
How can I inspect the running container to check where my local data should be loaded?
you can do 2 things:
docker inspect design_patterns
will show you some info about the running container
or just get into the container
docker exec -it design_patterns bash
this will drop you into a bash shell into the container, then you can inspect the current state with regular bash commands

Resources