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 10 years ago
- Reactions: 27
- Comments: 37 (3 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
Encountered here too
Docker compose v2 doesnβt suffer this limitation
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_networkis being used.Two and a half years later, we still have the same problem.
Iβm also running into the exact same problem. Here are my versions:
and hereβs the gist of my
docker-compose.ymlfile:(some part redacted)
With this
docker-compose.yml, the error will happen when thebackendcontainer is already running and we attempt to execute anotherdocker runcommand related tobackend.Hereβs a concrete example. Assuming that
backendis 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 downprior to doingdocker-compose run backend. Eg, this is what I do now:@simwai
versionin compose file is unrelated (and obsolete) I canβt reproduce issue using latest docker compose release, please provide a reproduction example if you doSame 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?
Workaround works but I am using run to prevent downtime. After switching to host mode due to performance considerations run command is useless.
I got the same issue. Trying to run a one-off command to service previously started via
docker-composewithnetwork_mode: hostfails 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 hostto 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.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
@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)