Introduction
this is part 17 from the journey it's a long journey(360 day) so go please check previous parts , and if you need to walk in the journey with me please make sure to follow because I may post more than once in 1 Day but surely I will post daily at least one 😍.
And I will cover lot of tools as we move on.
Download app_017
if you follow part 9
cd location/DevOpsJourney/
git pull
cd app_017/
replace location with where you put the DevOpsJourney
if your new go to part 9 and do same steps will download old lecture files and new one.
Dockerfile
In this short tutorial we are going to share data between 2 containers using volume
in this app_017 I add something to docker file (only for container1)
volume ["/app/share"]
it's mean we are going to create a volume attached to it while building the image
Building
I am going to build my images
docker image build -t app_017_1 container1/
we can notice that he create the volume while building
docker image build -t app_017_2 container2/
running containers and share data
on the left
docker run --rm --name app_017_1 -exec -it app_017_1 sh
we need the --name here because we are going to use it to mention the volume in container2
inside the shell
echo "Hello i am inside container 1" > share/file.txt
echo is an linux also windows program to write some text into a file it goes like
echo string > location/file.extension
then to make sure that my file created
cat share/file.txt
we can see our file successfully created.
let's move to the right split
docker run --rm --name app_017_2 --volumes-from app_017_1 -exec -it app_017_2 sh
it's a long command but we cover all what those mean already in previous lectures what I care for now --volumes-from app0171 , app0171 is the --name of first container.
inside the shell let's make share that our shared file is here
ls
cat share/file.txt
we can see that we are able to share the files between containers.