How to rebuild docker container in docker-compose.yml?

前端 未结 10 2022
闹比i
闹比i 2021-01-29 17:14

There are scope of services which defined in docker-compose.yml. These service have been started. I need to rebuild only one of these and start it without up other services. I r

相关标签:
10条回答
  • 2021-01-29 18:00
    docker-compose stop nginx # stop if running
    docker-compose rm -f nginx # remove without confirmation
    docker-compose build nginx # build
    docker-compose up -d nginx # create and start in background
    

    Removing container with rm is essential. Without removing, Docker will start old container.

    0 讨论(0)
  • 2021-01-29 18:02

    With docker-compose 1.19 up

    docker-compose up --build --force-recreate --no-deps [-d] [<service_name>..]
    

    Without one or more service_name arguments all images will be built if missing and all containers will be recreated.

    From the help menu

    Options:
        -d, --detach        Detached mode: Run containers in the background,
                            print new container names. Incompatible with
                            --abort-on-container-exit.
        --no-deps           Don't start linked services.
        --force-recreate    Recreate containers even if their configuration
                            and image haven't changed.
        --build             Build images before starting containers.
    

    Without cache

    To force a rebuild to ignore cached layers, we have to first build a new image

    docker-compose build --no-cache [<service_name>..]
    

    From the help menu

    Options:
        --force-rm              Always remove intermediate containers.
        -m, --memory MEM        Set memory limit for the build container.
        --no-cache              Do not use cache when building the image.
        --no-rm                 Do not remove intermediate containers after a successful build.
    

    Then recreate the container

    docker-compose up --force-recreate --no-deps [-d] [<service_name>..]
    
    0 讨论(0)
  • 2021-01-29 18:05

    Maybe these steps are not quite correct, but I do like this:

    stop docker compose: $ docker-compose down

    remove the container: $ docker system prune -a

    start docker compose: $ docker-compose up -d

    0 讨论(0)
  • 2021-01-29 18:05

    Only:

    $ docker-compose restart [yml_service_name]
    
    0 讨论(0)
提交回复
热议问题