Introduction
this is part 14 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_014
if you follow part 9
cd location/DevOpsJourney/app_014/
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.
The Problem
so the problem with our Docker right now is every time we need to make a change for our code we need to rebuild image , is time and space waste , and not a pragmatic way to do.
Let's see the problem
first let's build our app
docker image build -t app_014 .
and let's run our app
docker run -it app_014
our app will print a message and save a number to a file.txt
let's take a look inside our app
it will save number 12 to a file.txt
let's take a look inside our app folder , as we know docker will create an app folder inside his own image because we asked to do this , check #009 Dockerfile
so to access this app folder using interactive shell
docker run -it app_014 sh
inside the interactive shell
cat file.txt
we can see that 12 is stored
Time to make a change
let's change 12 in our app.py to 666
first exit our interactive shell
exit
I use vim as my text editor(actually as complete IDE ;D )
let's take a look again inside the container
docker run -it app_014 sh
inside the interactive shell
cat file.txt
we can see that isn't changed
The fix
we can fix our problem using -v (volume)
docker run -it --rm --name app_014 -v $PWD:/app app_014
$PWD is a default variable in linux it store the home url
in our case , we use in docker alpine which is a linux based distro , /app is the directory we make in Dockerfile to store our app
again let's take a look inside
docker run -it --rm --name app_014 -v $PWD:/app app_014 sh
inside the interactive shell
cat app.py
as we see we got 666 without rebuild our image!
let's try 999
see as soon I change my code is got updated inside the image with out rebuild the image.
Top comments (0)