Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

409
Views
Copy files from container fs to sibling container

Say I am running in a container which was started with:

docker run -v /var/run/docker.sock:/var/run/docker.sock foo

then I launch another container from within the above one:

docker run -v /var/run/docker.sock:/var/run/docker.sock bar

my question is - is the /var/run/docker.sock from the second command pointing to the same /var/run/docker.sock as the first command?

The containers should be siblings, so my second question is - how can I get files from the "outer" container into the "inner" the container using the -v option? I am looking to do:

docker run -v "/foo:/bar" -v /var/run/docker.sock:/var/run/docker.sock bar
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

When one mounts a docker socket into a container, s/he's giving the container control over the instance of docker running on the host.

You can think of this as analogous to giving multiple containers the URL of a website. Whatever an analogous containers does affects the analogous website, and those changes will be visible to all.

In concrete terms, under this setup, there is no hierarchy of containers: Just multiple containers controlling the same docker daemon that could have otherwise been controlled via the docker command on the host. Each container will have an equal ability to do pretty much anything on the host, via the docker daemon, and the isolation provided by containers by default will almost entirely be subverted.

For this reason, docker in docker has some inherent security implications, but more on those can be found elsewhere on the internet.

To answer your second question, copying files between containers involves running a command that emits the contents of the file in the source container, and piping it to a command that writes to the destination file in the destination container. For example:

docker exec container1 cat /source/file | docker exec -i container2 bash -c "cat > /dest/file"

Copying multiple files could involve creating a tarball in the source and expanding it in the other:

docker exec container1 tar -C /source -c dir| docker exec -i container2 tar -C /dest -x

As a convenience, and for situations where a shell or tar are not available within a container, docker cp can be used to copy files from a container to the host. By copying a file from a source container to the host, and then to the destination container, you can arrive at the same solution, at the cost of a a bit of temporary storage. For example:

docker cp container1:/source/file file
docker cp file container2:/dest/file

You were onto something, though. An alternative would be to mount a directory from the host into both containers and communicate via that directory. For example:

mkdir shared
docker run -d --name=container1 -v $PWD/shared:/mnt/share image command
docker run -d --name=container2 -v $PWD/shared:/mnt/share image command

Typos notwithstanding, the example above will result in two containers becoming available. The processes in those two containers may share files via /mnt/share with will be backed by the shared/ directory on the host.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!