How to restart a single container with docker-compose

后端 未结 9 1804
失恋的感觉
失恋的感觉 2020-12-02 03:27

I have a docker-compose.yml file that contains 4 containers: redis, postgres, api, worker

During the development of worker, I often need to restart it i

相关标签:
9条回答
  • 2020-12-02 04:13

    Following command

    docker-compose restart worker
    

    will just STOP and START the container. i.e without loading any changes from the docker-compose.xml

    STOP is similar to hibernating in PC . Hence stop/start will not look for any changes made in configuration file . To reload from the recipe of container (docker-compose.xml) we need to remove and create the container (Similar analogy to rebooting the PC )

    So commands will be as following

    docker-compose stop worker       // go to hibernate
    docker-compose rm worker        // shutdown the PC 
    docker-compose create worker     // create the container from image and put it in hibernate
    
    docker-compose start worker //bring container to life from hibernation
    
    0 讨论(0)
  • 2020-12-02 04:15

    The answer's here are talking about the reflection of the change on the docker-compose.yml file.

    But what if I want to incorporate the changes I have done in my code, and I believe that will be only possible by rebuilding the image and that I do with following commands

    1. docker container stop

    docker stop container-id
    

    2. docker container removal

    docker rm container-id
    

    3. docker image removal

    docker rmi image-id
    

    4. compose the container again

    docker-compose up container-name
    
    0 讨论(0)
  • 2020-12-02 04:21

    Simple 'docker' command knows nothing about 'worker' container. Use command like this

    docker-compose -f docker-compose.yml restart worker

    0 讨论(0)
提交回复
热议问题