compose icon indicating copy to clipboard operation
compose copied to clipboard

Running one-off containers does not work in 1.3, "is already in use"

Open kevinsimper opened this issue 11 years ago • 12 comments

I used to run tests in docker by running one-off containers, but that is not possible in 1.3.

When i try i says

$ docker-compose run backend npm test
Conflict. The name "app_backend_run_1" is already in use by container e46cb8f520ad. You have to delete (or rename) that container to be able to reuse that name.

Same commando that I used before.

I have tried running docker-compose up and also docker-compose migrate-to-labels

How do you run one-off containers, like the docs propose https://github.com/docker/compose/blob/master/docs/cli.md#run

kevinsimper avatar Jun 28 '15 17:06 kevinsimper

Unfortunately I don't think the migration removes the one off containers. You'll have to run docker rm app_backend_run_1 to remove the container first.

dnephin avatar Jun 28 '15 19:06 dnephin

But then the docs should be changed, because that does not say anything about that.

And what should be the reason that you can not launch a container that will have another cmd, and have the other still running? That was how it was working before.

kevinsimper avatar Jun 28 '15 20:06 kevinsimper

I have the same issue. docker rm app_backend_run_1 works one time, but then the next time it increments the number to app_backend_run_2. So I have to run docker rm again and again.

c0 avatar Jun 30 '15 20:06 c0

Yeah, I'm seeing the same issue here. It's pretty terrible for development, TBH. TDD in this environment is really frustrating. Development environment standardization is 99% of the reason our organization is using docker - we need to be able to run tests with a single command.

willbarrett avatar Jul 01 '15 19:07 willbarrett

If you're getting it repeatedly it's because you've got multiple *_run_* containers sitting around (_1, _2, _3 etc) from before the transition to labels. If you remove them all, the error should go away for good.

Perhaps we should detect one-off legacy containers and add another instruction to the help message. Something like:

As of Compose 1.3.0, containers are identified with labels instead of naming convention. If you want to continue using these containers, run:

    $ docker-compose migrate-to-labels

Alternatively, remove them:

    $ docker rm -f myapp_web_1 myapp_redis_1

You should also remove your one-off containers:

    $ docker rm -f myapp_web_run_1 myapp_web_run_2 myapp_web_run_3

aanand avatar Jul 02 '15 08:07 aanand

I've migrated to labels and docker rm'd all of the one-off containers (e.g. docker rm myapp_web_run_1) and this works as expected for a while.

Then around 20 times I start getting Conflict. The name "myapp_run_21" is already in use. So I rm myapp_run_{1-21} and it's fine for a while. It keeps coming back though.

Anything I can provide to help debug this?

c0 avatar Jul 02 '15 15:07 c0

hmm, that is unexpected.

@c0 (or anyone else experiencing this problem) It'd be great to get something like this (before doing the rm) to help debug it:

docker ps -a | grep myapp_web_run | awk '{ print $1 }' | xargs docker inspect -f '{{.Name}} {{.Config.Labels}}'

dnephin avatar Jul 03 '15 01:07 dnephin

See #1643.

aanand avatar Jul 03 '15 12:07 aanand

@dnephin It took a while for the error to return, but it did start happening on run # 31. When I ran your command, it shows over 2,500 containers ?!

Full dump: https://gist.github.com/c0/59e9b385bf47648b31ce

c0 avatar Jul 08 '15 13:07 c0

@c0 it looks like you've simply accrued a vast number of containers over time from running docker-compose run a lot. If you remove them all, you'll stop getting the error.

aanand avatar Jul 08 '15 15:07 aanand

@aanand what's the difference in the two sets? The first 30 have labels and the other 2,560 don't? I'm not fully clear on where these came from (< v1.3 of docker compose?)

c0 avatar Jul 08 '15 16:07 c0

@c0 yes, I think something must be running an earlier version of compose and creating those container. Maybe a crontab somewhere?

dnephin avatar Jul 08 '15 16:07 dnephin