Pure.Krome
Pure.Krome

Reputation: 86957

How to just build/update a single Docker image instead of all services after docker-compose up?

I have a docker-compose.yml file with a few services declared within.

When I type docker-compose up they all start.

Now, I wish to fix just one of them. I usually then docker-compose down which stops all of them. Instead, I'm hoping to just pull down the one service I need to fix, fix it (build/compile/etc) and then start up that single Docker image.

So is there a way I can do this instead of doing:

Upvotes: 0

Views: 143

Answers (2)

Moreno
Moreno

Reputation: 546

We normally go with:

docker-compose stop servicename
docker-compose rm servicename

and then:

docker-compose up -d servicename

Upvotes: 1

techtabu
techtabu

Reputation: 26947

You re-build the images and do a docker-compose up, which will automatically detect the the image is updated and recreate the service. Down side of building an images while the container from that image is running is that it will leave a none image, since docker won't delete image. You could overcome by removing the container from that image before hand by either one of these commands.

docker rm -vf <container-name>
docker rm -vr <container-id>

If that is inconvenient for you could delete the none images afterwards by,

docker rmi <image-id>

Also, if you have multiple none images hanging, you could remove all by,

docker images -q --filter "dangling=true" | xargs docker rmi -f

Upvotes: 1

Related Questions