compose: docker-compose run fails for running network_mode=host services
For a network_mode: host
service,
version: '2'
services:
redis:
image: redis
network_mode: host
$ docker-compose version
docker-compose version 1.11.1, build 7c5d5e4
docker-py version: 2.0.2
CPython version: 2.7.13
OpenSSL version: OpenSSL 1.0.1t 3 May 2016
$ hostname
localhost
$ docker-compose run --rm redis hostname
localhost
The docker-compose run
command fails if the service is running:
$ docker-compose up -d redis
Starting composetest_redis_1
$ docker-compose run --rm redis hostname
ERROR: Cannot create container for service redis: Conflicting options: host type networking can't be used with links. This would result in undefined behavior
$ docker-compose stop redis
Stopping composetest_redis_1 ... done
$ docker-compose run --rm redis hostname
localhost
It looks like docker-compose --verbose run
tries to do some --link
trickery against the running container, but this is not compatible with the --net host
:
compose.cli.verbose_proxy.proxy_callable: docker create_host_config -> {'Binds': [],
'Links': ['composetest_redis_1:composetest_redis_1',
'composetest_redis_1:redis',
'composetest_redis_1:redis_1'],
'LogConfig': {'Config': {}, 'Type': u''},
'NetworkMode': 'host',
'PortBindings': {},
'VolumesFrom': []}
ERROR: compose.cli.main.main: Cannot create container for service redis: Conflicting options: host type networking can't be used with links. This would result in undefined behavior
Possibly related: #2480
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 25
- Comments: 34 (1 by maintainers)
The problem does not go away by doing nothing, then flagging it as stale, and finally closing the ticket. Bugs need to be fixed, not managed
This issue has been automatically marked as not stale anymore due to the recent activity.
Same issue.
This is still relevant π
likewise
Same issue
Docker compose v2 doesnβt suffer this limitation
Encountered here too
I close the issue, Compose v2 works as expected and Compose v1 is end-of-life Tested with @hholst80 sample
This is also happening in https://github.com/akvo/akvo-rsr where
network_mode: service:main_network
is being used.Iβm also running into the exact same problem. Here are my versions:
and hereβs the gist of my
docker-compose.yml
file:(some part redacted)
With this
docker-compose.yml
, the error will happen when thebackend
container is already running and we attempt to execute anotherdocker run
command related tobackend
.Hereβs a concrete example. Assuming that
backend
is already running, this is the behavior:You will immediately see this error:
Workaround
Thereβs a workaround for this issue that works for me, which is to do a
docker-compose down
prior to doingdocker-compose run backend
. Eg, this is what I do now:Same problem here ⦠unbelievable how after years this is still present⦠using docker-compose up
I am also seeing the same issue in a different use-case, is there any way to disable the links docker-compose creates automatically? What is the way forward on this issue? It is open since 3 years, is there any way we can escalate this?
I got the same issue. Trying to run a one-off command to service previously started via
docker-compose
withnetwork_mode: host
fails with error.verbose output:
Otherwise speaking, compose is trying to create a temporary container for a one-off command and link it to the existing container. Proper fix could be passing
--network-mode host
to a run command and donβt use the link when it is passed.Workaround: donβt mess with the
run
, useexec
:I am also encountering the same problem on a container with
network_mode: host
.As a workaround, I had to stop my running containers, then run my separate run command.
Two and a half years later, we still have the same problem.
@nathantsoi
docker-compose run ...
does not enter the container, it makes a new container with the same settings. To βenterβ a running container you would usedocker-compose exec
.The reason turned out to be a misleading error message in my case. An instance of the container was in restart mode, and docker compose got confused (I have not links, but network_mode=host)