How To Rebuild Docker Container In Docker-Compose.Yml?
So I learned that there are a lot of services that are defined docker-compose.yml. I started a few of these services. I want to create only one of these and then start it up without using the other services
These are the commands I have run :
docker-compose up -d # run all services
docker-compose stop nginx # stop only one. but it still running !!!
docker-compose build --no-cache nginx
docker-compose up -d --no-deps # link nginx to other services
I got a nginx container by the end and I also learned that docker-compose will not kill all running containers! How does docker rebuild containers?
With docker-compose 1.19 up
docker-compose up --build --force-recreate --no-deps [-d] [..]
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 rebuild --no-cache [..]
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 containerdocker-compose up --force-recreate --no-deps [-d] [..]