193

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?

Marc Perrin-Pelletier
  • 12,696
  • 8
  • 28
  • 36

4 Answers4

379

Yes, use the name of the service:

docker-compose build elasticsearch
dnephin
  • 25,944
  • 9
  • 55
  • 45
54
docker-compose up -d --no-deps --build <service_name>

Source

FTM
  • 1,887
  • 17
  • 34
43

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:
      .....
Rambou
  • 968
  • 9
  • 22
2

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

pras1101
  • 31
  • 2