-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docker-compose run fails for running network_mode=host services #4548
Comments
I'm also running into the exact same problem. Here are my versions:
and here's the gist of my (some part redacted)
With this Here's a concrete example. Assuming that
You will immediately see this error:
WorkaroundThere's a workaround for this issue that works for me, which is to do a
|
Running into the same issue. There should be a way to bypass the automatic linking that compose is trying to do. The workaround that @sivabudh describes isn't really ideal if the command being run in the second step takes a non-trivial amount of time. |
Agreed with @usmanm on his comments. Fortunately, my app update takes roughly 6 seconds, and we are lucky that our apps can have daily maintenance window. |
This is still relevant 👍 |
Same issue. |
Encountered here too |
Same issue |
likewise |
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) |
This is still reproducible in docker-compose version 1.22.0, build f46880f.
|
same here. this is a problem when i bring up an array of services with |
The same problem occurs during |
@nathantsoi |
Two and a half years later, we still have the same problem.
|
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. |
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. |
I encountered the same problem. |
I am also encountering the same problem on a container with As a workaround, I had to stop my running containers, then run my separate run command. $ docker-compose up -d
docker-compose_bar_1 is up-to-date
docker-compose_foo_1 is up-to-date
$ docker-compose run --rm bar echo hello world
ERROR: Cannot create container for service bar: conflicting options: host type networking can't be used with links. This would result in undefined behavior
$ docker-compose stop
$ docker-compose run --rm bar echo hello world
hello world
$ |
I got the same issue. Trying to run a one-off command to service previously started via
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 Workaround: don't mess with the
|
with |
Adding my comment to prevent bot from marking as stale. I encountered this issue as well.
Had to bring down container that was "up" before executing |
I workarounded it (at least for openvpn) by creating a sibling container with -cmd prefix without network mode host. Example: version: '2'
services:
openvpn:
cap_add:
- NET_ADMIN
image: kylemanna/openvpn
container_name: openvpn
ports:
- "1194:1194/udp"
restart: always
volumes:
- ./openvpn-data/conf:/etc/openvpn
network_mode: host
pid: host
openvpn-cmd:
image: kylemanna/openvpn
container_name: openvpn-cmd
volumes:
- ./openvpn-data/conf:/etc/openvpn And instead of |
Workaround works but I am using run to prevent downtime. After switching to host mode due to performance considerations run command is useless. |
You should be able to also do this if your command is simple enough:
Where SERVICE is the service in question in your docker-compose.yml file and COMMAND is the command you want to run. You'll have to add all the relevant args to docker run manually, though. It would be nice to be able to run services with host mode networking, even if the networking part were disabled. |
I am also seeing the same issue in a different use-case, is there any way to disable the links docker-compose creates automatically? |
Same problem here ... unbelievable how after years this is still present... using docker-compose up |
Have you tried changing the version in the docker-config.yml to 3.4?
This appears to have fixed several issues for me, including the host-mode. |
Using syntax version 3.7 and just came across this also. Like everyone has already explained, this only happens when there's an existing container running, so my suggestion is to use docker exec to execute in the already running container instead of running a new one. |
This is also happening in https://github.com/akvo/akvo-rsr where $ docker-compose up -d
Creating akvo-rsr_rsr-memcached_1 ... done
Creating akvo-rsr_rsrdbhost_1 ... done
Creating akvo-rsr_mainnetwork_1 ... done
Creating akvo-rsr_web_1 ... done
Creating akvo-rsr_reports_1 ... done
Creating akvo-rsr_nginx_1 ... done
$ docker-compose run --rm web echo lol
Starting akvo-rsr_mainnetwork_1 ... done
ERROR: Cannot create container for service web: conflicting options: container type network can't be used with links. This would result in undefined behavior |
Still relevant. I wanted to use docker-compose run in order to prevent downtime. So having two containers of that service running at the same time was my goal. |
Docker compose v2 doesn't suffer this limitation
|
I close the issue, Compose v2 works as expected and Compose v1 is end-of-life > bat compose.yaml
───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ File: compose.yaml
│ Size: 152 B
───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ services:
2 │ foo:
3 │ image: debian
4 │ command: sleep inf
5 │ network_mode: host
6 │ bar:
7 │ image: debian
8 │ command: sleep inf
9 │ network_mode: host
───────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
> docker compose up -d
[+] Running 3/3
⠿ foo Pulled 5.6s
⠿ cfc947b533a3 Pull complete 3.2s
⠿ bar Pulled 5.6s
[+] Running 2/2
⠿ Container issue-4548-foo-1 Started 0.4s
⠿ Container issue-4548-bar-1 Started |
Docker Compose version v2.10.2 Error response from daemon: conflicting options: host type networking can't be used with links. This would result in undefined behavior
network_mode: "host" cannot be mixed with links.Solution:
|
Unfortunately, it does. This problem still occurs on v2 and v3 and v3.4. |
@simwai |
Works just fine with latest Compose spec and Docker Engine 26.1.0: # cat compose.yaml
services:
foo:
image: debian
command: sleep inf
network_mode: host
bar:
image: debian
command: sleep inf
network_mode: host |
For a
network_mode: host
service,The
docker-compose run
command fails if the service is running: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
:Possibly related: #2480
The text was updated successfully, but these errors were encountered: