skip to Main Content

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

  1. stop the running containers (docker-compose stop)
  2. 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


  1. 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 key UpperDir 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.

    Login or Signup to reply.
  2. 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:

    1. docker build the new image
    2. docker run it
    3. Attach it to the load balancer (now traffic goes to both old and new containers)
    4. Test that the new container works correctly
    5. Detach the old container from the load balancer
    6. docker stop && docker rm the old container

    If 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search