docker compose build single container

DockerDocker Compose

Docker Problem Overview


Using Compose, if I run docker-compose build, it will rebuild all the containers :

> docker-compose build
Building elasticsearch
Step 1 : FROM elasticsearch:2.1
 ---> a05cc7ed3f32
Step 2 : RUN /usr/share/elasticsearch/bin/plugin install analysis-phonetic
 ---> Using cache
 ---> ec07bbdb8a18
Successfully built ec07bbdb8a18
Building search
Step 1 : FROM php:5.5.28-fpm
 ---> fcd24d1058c0
...

Even when rebuilding using cache, this takes time. So my question is:

Is there a way to rebuild only one specific container?

Docker Solutions


Solution 1 - Docker

Yes, use the name of the service:

docker-compose build elasticsearch

Solution 2 - Docker

docker-compose up -d --no-deps --build <service_name>

Source

Solution 3 - Docker

if you want to run and recreate a specific service inside your docker-compose file you can do it the same way as @dnephin proposed, like

$ docker-compose up -d --force-recreate --no-deps --build service_name

Suppose your docker-compose.yml file is like

version: '3'
services:
  service_1:
      .....
  service_2:
      .....

Solution 4 - Docker

You could added --no-start flag to docker-compose, and start later since you will only build one service.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMarc Perrin-PelletierView Question on Stackoverflow
Solution 1 - DockerdnephinView Answer on Stackoverflow
Solution 2 - DockerFTMView Answer on Stackoverflow
Solution 3 - DockerRambouView Answer on Stackoverflow
Solution 4 - Dockerpras1101View Answer on Stackoverflow