2
votes

I have working docker container. I see my site (and it's working normally)in browser through 172.17.0.2:8000 instead of www-local.dev-build.com. I've tried to run docker with --add-host (172.17.0.2 and 127.0.0.1) and add the same string in /etc/hosts. Not working. What's wrong? I'm confused.

docker info (container number is other because it is older container)

Containers: 1
 Running: 1
 Paused: 0
 Stopped: 0
Images: 4
Server Version: 17.03.0-ce
Storage Driver: aufs
 Root Dir: /var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 7
 Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins: 
 Volume: local
 Network: bridge host macvlan null overlay
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 977c511eda0925a723debdc94d09459af49d082a
runc version: a01dafd48bc1c7cc12bdb01206f9fea7dd6feb70
init version: 949e6fa
Security Options:
 apparmor
 seccomp
  Profile: default
Kernel Version: 4.8.0-41-generic
Operating System: Ubuntu 16.04.2 LTS
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 7.796 GiB
Name: pc-linux
ID: PBV5:TOE6:2O5T:C7YG:GONP:SPSK:IVK2:YYGP:AEN3:HAYT:VOUK:QK7A
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
WARNING: No swap limit support
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

docker version

Client:
 Version:      17.03.0-ce
 API version:  1.26
 Go version:   go1.7.5
 Git commit:   3a232c8
 Built:        Tue Feb 28 08:01:32 2017
 OS/Arch:      linux/amd64

Server:
 Version:      17.03.0-ce
 API version:  1.26 (minimum version 1.12)
 Go version:   go1.7.5
 Git commit:   3a232c8
 Built:        Tue Feb 28 08:01:32 2017
 OS/Arch:      linux/amd64
 Experimental: false

ping www-local.dev-build.com

PING www-local.dev-build.com (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.061 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.058 ms
64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.104 ms
64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.065 ms
64 bytes from localhost (127.0.0.1): icmp_seq=5 ttl=64 time=0.113 ms
^C
--- www-local.dev-build.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4082ms
rtt min/avg/max/mdev = 0.058/0.080/0.113/0.024 ms

cat /etc/hosts

127.0.0.1   localhost
127.0.1.1   pc-linux
127.0.0.1   www-local.dev-build.com
# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

cat /var/lib/docker/containers/ec1cc64d0c5c9c163a82191e171aed15cb11f73033eff3266e0e3273c9871b28/hosts

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
172.17.0.2      ec1cc64d0c5c

P. S. I;ve tested all troubleshoooting section in https://docs.docker.com/engine/installation/linux/linux-postinstall Everything's OK. But my problem still here.

1

1 Answers

1
votes

If you wan't to access your containerized website from your host, then you have to associate your local domain name to the docker container IP:

In the host's etc/hosts

172.17.0.2   www-local.dev-build.com

But this IP could change if you run multiple docker containers (depending on their start order). It's probably a better idea to publish the containerized application port on host. For that you can docker run your image with the -p8000:8000 to be able to reach your container's network from the host port 8000. For instance:

docker run -it --name myapp -p8000:8000 myappimage

Then your host's etc/hosts should be:

127.0.0.1   www-local.dev-build.com

And reach your application in host's browser through http(s)://www-local.dev-build.com:8000.