compose icon indicating copy to clipboard operation
compose copied to clipboard

[BUG] Can't run compose file with host network

Open ParSal123 opened this issue 2 years ago • 2 comments

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

ParSal123 avatar Oct 01 '23 12:10 ParSal123

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 avatar Oct 02 '23 06:10 ndeloof

@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

ElSamhaa avatar Jan 18 '24 11:01 ElSamhaa

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

ndeloof avatar May 28 '24 06:05 ndeloof