I have a docker-composer setup in which i am uploading source code for server say flask api . Now when i change my python code, I have to follow steps like this
- stop the running containers (docker-compose stop)
- build and load updated code in container (docker-compose up –build)
This take a bit long time . Is there any better way ? Like update code in the running docker and then restarting Apache server without stopping whole container ?
2
Answers
There are few dirty ways you can modify file system of running container.
First you need to find the path of directory which is used as runtime root for container. Run
docker container inspect id/name
. Look for the keyUpperDir
in JSON output. You can edit/copy/delete files in that directory.Another way is to get the process ID of the process running within container. Go to the
/proc/process_id/root
directory. This is the root directory for the process running inside docker. You can edit it on the fly and changes will appear in the container.You can run the
docker build
while the old container is still running, and your downtime is limited to the changeover period.It can be helpful for a couple of reasons to put a load balancer in front of your container. Depending on your application this could be a “dumb” load balancer like HAProxy, or a full Web server like nginx, or something your cloud provider makes available. This allows you to have multiple copies of the application running at once, possibly on different hosts (helps for scaling and reliability). In this case the sequence becomes:
docker build
the new imagedocker run
itdocker stop && docker rm
the old containerIf you don’t mind heavier-weight infrastructure, this sequence is basically exactly what happens when you change the image tag in a Kubernetes Deployment object, but adopting Kubernetes is something of a substantial commitment.