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

Better Stack Team
Updated on April 14, 2023

To rebuild a Docker container specified in a docker-compose.yml file, you can use the docker-compose build command. Here are the steps to rebuild a container:

  1. Navigate to the directory containing the docker-compose.yml file.
  2. Run the docker-compose build command with the name of the service you want to rebuild. For example, if your docker-compose.yml file specifies a service named web, you would run:

     
    docker-compose build web
    
  3. This will rebuild the web service, including any dependencies specified in the docker-compose.yml file.

  4. Once the build is complete, you can start the containers using the docker-compose up command. If you want to start the containers in detached mode, you can use the d option:

     
    docker-compose up -d
    

    This will start the containers and run them in the background.

Note that if you make changes to the docker-compose.yml file itself, you may need to use the docker-compose up command with the --build option to rebuild all of the services:

 
docker-compose up --build

This will rebuild all of the services specified in the docker-compose.yml file, regardless of whether they have changed.

Got an article suggestion? Let us know
Explore more
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

We are hiring.

Software is our way of making the world a tiny bit better. We build tools for the makers of tomorrow.

Explore all positions →

Reliability is the
ultimate feature

Delightful observability tools that turn your logs & monitoring into a secret weapon for shipping better software faster.

Explore Better Stack