Marc Perrin-Pelletier
Marc Perrin-Pelletier

Reputation: 13506

docker compose build single container

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?

Upvotes: 209

Views: 162345

Answers (4)

pras1101
pras1101

Reputation: 41

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

Upvotes: 3

Rambou
Rambou

Reputation: 1058

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:
      .....

Upvotes: 50

FTM
FTM

Reputation: 2067

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

Source

Upvotes: 64

dnephin
dnephin

Reputation: 28150

Yes, use the name of the service:

docker-compose build elasticsearch

Upvotes: 413

Related Questions