DEV Community

Hanane Kacemi
Hanane Kacemi

Posted on

TIL: using --no-deps with docker compose

Currently, I am working on a Laravel project with two containers: one for the web app and the other for the database.

Previously, whenever I needed to update the image used by the container hosting the web app, I had to stop both containers using docker compose stop app db, remove them with docker compose rm -v app db, execute docker compose down, and finally rebuild to apply changes to the desired container using docker compose up --build -d

As you might guess, this process required me to export the database, even if I only wanted to apply changes to the app container.

Recently, while watching some tutorials related to Docker and Docker Compose, I learned about the --no-deps option. This option allows us to apply changes to one container without affecting the other dependent containers.

Now, whenever I want to recreate the app container using a new image, I simply run:

docker compose stop app
docker rm app
docker compose up -d --no-deps app

There's no need to export the database, remove the database container, or import it again. This process is much easier for me now.

Thanks for reading!

Top comments (0)