Adam K Dean
Posted on June 1, 2015
Originally posted on June 1st, 2015 (more info)
Note: this was posted back in 2015 during the infancy of docker and modern containerisation. These days, we're able to simply use volumes. For more information on the modern way to do this, see docker volumes.
Create data volume container:
docker run -d \
-v /var/test/ \
--name test-data \
busybox
Start one container using it:
docker run -d \
--name test-1 \
--volumes-from test-data \
adamkdean/baseimage bash -c "while true; do echo 'ping'; sleep 5; done"
Start another using it:
docker run -d \
--name test-2 \
--volumes-from test-data \
adamkdean/baseimage bash -c "while true; do echo 'ping'; sleep 5; done"
Attach to the first:
docker exec -ti test-1 bash
root@7bfff33a2309:/# cd /var/test/
root@7bfff33a2309:/var/test# ls
Attach to the second:
docker exec -ti test-2 bash
root@7bfff33a2309:/# cd /var/test/
root@69e9a3cc34a2:/var/test# ls
Create a file in the first one:
root@7bfff33a2309:/var/test# touch test-file
Check in the second one:
root@69e9a3cc34a2:/var/test# ls
test-file
Both test-1
and test-2
are sharing the data on the data volume container test-data
.
💖 💪 🙅 🚩
Adam K Dean
Posted on June 1, 2015
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
dotnet Building a Linux Based Minimal and Efficient .NET 8 Application Docker Image
November 24, 2024