Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to force-recreate and start only one container under docker-compose?

After I make any code change, my typical development steps are:

  1. Change code and build the jar file
  2. Build docker image that consumes the jar file
  3. Kill current "docker-compose up" command.
  4. Run "docker-compose up" again.

My docker-compose file has five services. On step 3, all the containers go down. Ideally, I just need to re-run my app container.

I am looking for a way to do the following in a batch script:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  1. Bring down the app container. The other four containers should continue to run.
  2. Build a new docker image
  3. Force docker-compose to recreate my app container and start it.

For step 1, looks like I can use "docker-compose kill myappname."

Step 2 is also straightforward.

I am wondering how I can accomplish step 3. Thanks.

>Solution :

You don’t need to stop the current container explicitly.

If your image has changed, docker compose will recognize it and recreate your container, when you run the up command again.

So, rebuild your image and run docker compose up.

If you use compose to build the image, add the --build flag to let it rebuild your image, after which the container is also recreated.

You cann also add the name off a specific service to your up command, i.e. docker compose up -d --build app

If the image hasnt changed, you cann add the --force-recreate flag.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading