Will --add-host cover the /etc/hosts inheritied from host when using --network=host ?
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 6.1k
- Forks
- 2.2k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 43
Description
Description
docker run -d --name ${module} --restart always \
-v /ava_app/${caCN}/ava-${caCN}-service-${module}:/ava_app/prod/app \
-v /ava_data/upload:/ava_data/upload \
-v /ava_data/logs:/ava_data/logs \
-v /ava_data/ftp:/ava_data/ftp \
-v /etc/localtime:/etc/localtime:ro \
-v /ava_app/timezone:/etc/timezone:ro \
--add-host fdfs.ava.com.cn:${localIP} \
--add-host dev.ava.com.cn:${localIP} \
--add-host redis.ava.com.cn:${localIP} \
--add-host db.ava.com.cn:${caMysqlHost} \
--add-host mq.ava.com.cn:${localIP} \
--add-host eureka8761:${localIP} \
--add-host eureka8861:${localIP} \
--add-host eureka8961:${localIP} \
--network=host ava/java:8
This is my command to create a container.
I use --network=host, then the /etc/hosts in container is the same to the file in host:
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.0.1 ava.app
192.168.35.204 gx.ava.com.cn
But after I add the --add-host then the /etc/hosts in container like this:
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
192.168.37.156 fdfs.ava.com.cn
192.168.37.156 dev.ava.com.cn
192.168.37.156 redis.ava.com.cn
192.168.37.156 db.ava.com.cn
192.168.37.156 mq.ava.com.cn
192.168.37.156 eureka8761
192.168.37.156 eureka8861
192.168.37.156 eureka8961
Reproduce
docker run -d --name ${module} --restart always \
-v /ava_app/${caCN}/ava-${caCN}-service-${module}:/ava_app/prod/app \
-v /ava_data/upload:/ava_data/upload \
-v /ava_data/logs:/ava_data/logs \
-v /ava_data/ftp:/ava_data/ftp \
-v /etc/localtime:/etc/localtime:ro \
-v /ava_app/timezone:/etc/timezone:ro \
--add-host fdfs.ava.com.cn:${localIP} \
--add-host dev.ava.com.cn:${localIP} \
--add-host redis.ava.com.cn:${localIP} \
--add-host db.ava.com.cn:${caMysqlHost} \
--add-host mq.ava.com.cn:${localIP} \
--add-host eureka8761:${localIP} \
--add-host eureka8861:${localIP} \
--add-host eureka8961:${localIP} \
--network=host ava/java:8
docker exec -it live bash
cat /etc/hosts
Expected behavior
No response
docker version
Client: Docker Engine - Community
Version: 20.10.8
API version: 1.41
Go version: go1.16.6
Git commit: 3967b7d
Built: Fri Jul 30 19:55:49 2021
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.8
API version: 1.41 (minimum version 1.12)
Go version: go1.16.6
Git commit: 75249d8
Built: Fri Jul 30 19:54:13 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.9
GitCommit: e25210fe30a0a703442421b0f60afac609f950a3
runc:
Version: 1.0.1
GitCommit: v1.0.1-0-g4144b63
docker-init:
Version: 0.19.0
GitCommit: de40ad0
docker info
Client:
Context: default
Debug Mode: false
Plugins:
app: Docker App (Docker Inc., v0.9.1-beta3)
buildx: Build with BuildKit (Docker Inc., v0.6.1-docker)
scan: Docker Scan (Docker Inc., v0.8.0)
Server:
Containers: 18
Running: 17
Paused: 0
Stopped: 1
Images: 7
Server Version: 20.10.8
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
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: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
Default Runtime: runc
Init Binary: docker-init
containerd version: e25210fe30a0a703442421b0f60afac609f950a3
runc version: v1.0.1-0-g4144b63
init version: de40ad0
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-1160.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 8
Total Memory: 15.51GiB
Name: ava.app
ID: J2JF:F6KR:JUCY:JPDC:RYIK:2MZ3:JFL4:JEUK:QPKS:RMG3:FC7R:THXJ
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
WARNING: IPv4 forwarding is disabled
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
You have mail in /var/spool/mail/root
Additional Info
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided docker run command using --network=host and --add-host, then inspect the result with docker exec and cat /etc/hosts. Compare the generated entries with the host file and determine the intended behavior for inherited entries; done means the behavior is clarified or a reproducible regression test and corresponding change are identified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker
- Domain
- cli, networking
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100