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

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


docker-compose up

$ docker-compose up -d --no-deps --build <service_name>

--no-deps - Don't start linked services.

--build - Build images before starting containers.


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


This should fix your problem:

docker-compose ps # lists all services (id, name)docker-compose stop <id/name> #this will stop only the selected containerdocker-compose rm <id/name> # this will remove the docker container permanently docker-compose up # builds/rebuilds all not already built container