I'm a Docker newbie and I fired the following command which successfully copied the file to a running container.
sudo docker cp app.py 943395e93d1d:/app/app.py
Note : The container was already contains a app.py and so my guess was that because app.py is running inside the container it will not allow the copy .
I did another thing now
sudo docker cp sample.txt 943395e93d1d:/app/sample.txt
Now this also went successfully .
My question : Will the sample.txt file continue to exist within the container even after I stop the container ? So that if I start it again the updated files are there .
Because that means I don't build the docker file again and again but just copy the files if there are changes in some assets of my application ?
Anything you copy in with docker cp
will be lost as soon as the container exits. I'd use this command sparingly. It's certainly not a way to update your code; re-run docker build
when your application changes.
(In typical use, with an interpreted language where just copying in source code is enough, re-running docker build
should be very quick. It will generally know to skip over time-consuming dependency installation and just COPY
in the new source code. Even if you only have a single container using Docker Compose to drive things will give you a single place to list out the options you need to run it.)