Manu
Manu

Reputation: 335

--add-host option does not work in docker

I have two servers with the same operating system (OS: Ubuntu 22.04.5 LTS x86_64) and both run Docker (Docker version 24.0.7, build 24.0.7-0ubuntu2~22.04.1). I'm trying to access host web-services from inside a container. I followed the instructions from https://docs.docker.com/reference/cli/docker/container/run/#add-host and used the "hello from host" example. On one system, it works; however, on another server, it fails to access the web-server.

Please help me to resolve the issue.

Thank you.

docker info

Client:
 Version:    24.0.7
 Context:    default
 Debug Mode: false

Server:
 Containers: 88
  Running: 0
  Paused: 0
  Stopped: 88
 Images: 26
 Server Version: 24.0.7
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  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: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 
 runc version: 
 init version: 
 Security Options:
  apparmor
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 5.15.0-119-generic
 Operating System: Ubuntu 22.04.5 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 2
 Total Memory: 7.746GiB
 Name: beamish
 ID: dc8ba74f-07f6-4561-a227-ed950578027c
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Edited:

Hi @DavidMaze

I am trying to reproduce "hello from host!" example at docs.docker.com/reference/cli/docker/container/run/#add-host.

I expect

hello from host!

in command line when I run

$docker run \
  --add-host=host.docker.internal:host-gateway \
  curlimages/curl -s host.docker.internal:8000/hello

However, I get no output. The command halts for a while.

Furthermore, for the same command. I get the expected output on a different server with same Ubuntu version installed.

I want to know why the same command is behaving differently on two different systems.

I hope, my query is clear now.

@HansKilian - as you can see above, I had made changes in my command.

Thank you, both.

Upvotes: 0

Views: 76

Answers (0)

Related Questions