214

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?

4 Answers 4

417

Yes, use the name of the service:

docker-compose build elasticsearch
Sign up to request clarification or add additional context in comments.

1 Comment

Use docker-compose build --no-cache elasticsearch to force a rebuild of an existing image
66
docker-compose up -d --no-deps --build <service_name>

Source

1 Comment

why you use -no-deps?
50

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

4 Comments

This wouldn't work, if it depends on something it would run everything it depends on.
Indeed question was about recreating that, i've updated the answer @MariusVanNieuwenhuyse
why you use force-recreate? is it recreating all or only that building service?
I had to use --build (with --force-recreate), even though I had previously, separately, done docker-compose build service_name. Otherwise it would just use my existing container.
4

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.