[BUG] Can't run compose file with host network
Description
I can't use host network in compose services.
Steps To Reproduce
services:
mysql:
image: mysql
networks:
hostnet: {}
networks:
hostnet:
external: true
name: host
This is my compose file which I copied from the docs (with minor modifications to run). When I do docker compose up I get:
[+] Running 1/1
✔ Container project-mysql-1 Created 0.1s
Attaching to project-mysql-1
Error response from daemon: network-scoped alias is supported only for containers in user defined networks
Compose Version
Docker Compose version 2.20.3
Docker Environment
Client:
Version: 24.0.5
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc.)
Version: 0.11.2
Path: /usr/lib/docker/cli-plugins/docker-buildx
compose: Docker Compose (Docker Inc.)
Version: 2.20.3
Path: /usr/lib/docker/cli-plugins/docker-compose
scan: Docker Scan (Docker Inc.)
Version: v0.1.0-280-gc7fa31d4c4
Path: /usr/lib/docker/cli-plugins/docker-scan
Server:
Containers: 3
Running: 0
Paused: 0
Stopped: 3
Images: 32
Server Version: 24.0.5
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Using metacopy: true
Native Overlay Diff: false
userxattr: false
Logging Driver: json-file
Cgroup Driver: systemd
Cgroup Version: 2
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc io.containerd.runc.v2
Default Runtime: runc
Init Binary: docker-init
containerd version: 091922f03c2762540fd057fba91260237ff86acb.m
runc version:
init version: de40ad0
Security Options:
seccomp
Profile: builtin
cgroupns
Kernel Version: 6.1.53-1-MANJARO
Operating System: Manjaro Linux
OSType: linux
Architecture: x86_64
Docker Root Dir: /var/lib/docker
Debug Mode: true
File Descriptors: 28
Goroutines: 59
System Time: 2023-10-01T16:21:20.898877997+03:30
EventsListeners: 0
Experimental: false
Live Restore Enabled: false
Anything else?
No response
host networking is not just a pre-defined network name, it must be enabled using network_mode:
services:
mysql:
image: mysql
network_mode: host
@ndeloof I think it counts as a bug as the example in the docs doesn't work https://github.com/compose-spec/compose-spec/blob/master/06-networks.md#host-or-none
indeed, this has been inherited from the legacy docker compose v1 documentation, by the time it was converted into "compose specification". Better fix the docs then