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!

👋 While you are here

Reinvent your career. Join DEV.

It takes one minute and is worth it for your career.

Get started

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay