docker on windows 10: container has no ip address - docker

First step: I loaded the Images from a local drive:
docker load -i postgres10.tar
docker load -i drupaldrush1.tar
Second step: I started the containers:
docker run -p5432:5432 postgres:10
docker run -p8081:8081 drupaldrush:1
Third step: displaying containers:
docker ps
results in:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b77bcc79d599 drupaldrush:1 "docker-php-entrypoi…" 33 seconds ago Up 32 seconds 80/tcp, 0.0.0.0:8081->8081/tcp flamboyant_easley
97b9ba5f2779 postgres:10 "docker-entrypoint.s…" About a minute ago Up About a minute 0.0.0.0:5432->5432/tcp competent_fermat
BUT container is not available under: localhost:8081
Fourth step: inspecting container:
docker inspect flamboyant_easley
resulting in (among other Information):
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {
"8081/tcp": [
{
"HostIp": "",
"HostPort": "8081"
}
]
},
and
"IPAddress": "172.17.0.3",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "d5e552bf9c57050fe2debfc7d38a784580309fa0b72c4854a563e78295128912",
"EndpointID": "f61b02c5997b2e391add348686f658b4c596dd60495365cee0fee539743d4792",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.3",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
Problem: The container is not available under localhost:8081 and not under 172.17.0.3: 8081 or 172.17.0.1:8081
Question: What do I have to do to make it run under localhost:8081?

The problems came from Docker for Windows. Now I got a Linux Laptop and everything works just fine.

Related

Cannot access container by "network_mode: host"

I cannnot use network_mode: host in docker in windows 10. I try difference images, it cannot too.
I post my docker-compose.yaml below.
docker-compose.yaml
homeassistant2:
container_name: hass2
image: homeassistant/home-assistant:0.112.2
network_mode: host
But when set the port mapping,everthing is fine
ports:
- '8123:8123'
# network_mode: host
My environmet is windows 10
I get some information from command docker inspect
I post some of it about network settings below.
"NetworkSettings": {
"Bridge": "",
"SandboxID": "f084a1e7e4966f0bff678e4120c1bcbc7afdd1c55d5164b1dc4a606470c43bcc",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {},
"SandboxKey": "/var/run/docker/netns/default",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"host": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "656b532cdc48c9e34e616ec0a38ef944c5e52e2dfca506ca99e53b4b16206000",
"EndpointID": "",
"Gateway": "",
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "",
"DriverOpts": null
}
}
}
}
]
If I need provide something else to analyze the problem, please tell me.
When running Docker under Windows or MacOS, you're actually running Docker in a Linux virtual machine. When you set network_mode: host, you're connecting the container to the network environment of the virtual machine. This is seldom going to be useful.
network_mode: host is really only going to make sense when running Docker natively on Linux.
You're better off sticking with port publishing.

How to use Docker api engine to exec cmd in container

How to use Docker api engine to exec command in container. I want to use the api docker to exec cmds in container via http calls
If you want to do exec the cmd in container you need to enter either id or name of the container, here the id is not similar to which we will get to see by executing docker ps -a, there is one EndPoint to fetch details in json of running containers i.e.
The result response as shown below
{
"Id": "ba7b20038dfe49d326788258eca42acb752405db835e09ffdf2705fdc16b7d17",
"Names": [
"/muruga"
],
"Image": "ubuntu",
"ImageID": "sha256:93fd78260bd1495afb484371928661f63e64be306b7ac48e2d13ce9422dfee26",
"Command": "/bin/bash",
"Created": 1544778203,
"Ports": [],
"Labels": {},
"State": "running",
"Status": "Up 3 seconds",
"HostConfig": {
"NetworkMode": "default"
},
"NetworkSettings": {
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "6204f5fc4d3689aebe589bd1eab4a94f73a249d69aa88772a800d94f1edc1ea6",
"EndpointID": "7509759b07f6463b4a0a88baa00a5f6834cf69615ac88bb8bc1dbd8557be7db3",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:02",
"DriverOpts": null
}
}
},
"Mounts": []
}
You need to use either id or name of the running container to create 'exec' instance i.e.
url===>Post /containers/{{id/name}}/exec
`Post data
{
"AttachStdin": true,
"AttachStdout": true,
"AttachStderr": true,
"DetachKeys": "ctrl-p,ctrl-q",
"Tty": true,
"Cmd": [
"bin/bash","-c","touch appa.py"
],
"Env": [
"FOO=bar",
"BAZ=quux"
],
"Privileged":true,
"User":"root"
}`
it returns the response 201 with json id, this id is unique every time exec instance post done it will return unique id, you need to copy this id and pass it to another url or endpoin
url===>post /exec/{{id(unique id which I mentioned in above from response)}}/start
post with following data
{
"Detach": true,
"Tty": false
}
it returns with 200 ok, you can get into container and check the execution of the commands

docker container is Kubernetes cluster can't access outer resources

I am rather new to Kubernetes and I am trying to start a kubernetes cluster and deploy some pods .
I have a image I want to build in order to perfrom a deployment of it so I am trying to build it's dockerfile but one of the steps in the dockerfile tries to access golobal resource :
curl --silent --location https://rpm.nodesource.com/setup_7.x
I keep getting this error message :
Connecting to rpm.nodesource.com (rpm.nodesource.com)|13.32.153.164|:443... failed: Connection timed out.
Connecting to rpm.nodesource.com (rpm.nodesource.com)|2600:9000:2116:2800:16:cdcc:51c0:93a1|:443... failed: Network is unreachable
I can see that container was able to resolve the dns name ( based on the IP it prints out in the message ) but is unable to access it.
my /etc/resolv.conf is :
search default.svc.cluster.local svc.cluster.local
nameserver 10.82.67.3
nameserver 10.233.0.3
nameserver 8.8.8.8
options ndots:2 timeout:2 attempts:2
my docker version is 17.05.0-ce
my OS is redhat 7.4
this is the Network part of the docker inpect command of the container :
"NetworkSettings": {
"Bridge": "",
"SandboxID": "a4a4c93d0ea19b48b84ef8556678f458405b32238542ede30a78229f82b55a12",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {},
"SandboxKey": "/var/run/docker/netns/a4a4c93d0ea1",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "66d74579ee50bc8289dfc58235188e262ebf707f2f0ae0ccb640524e6e9d3f22",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:02",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "655da32f8ecab7a4bba100594a1e242c60b27304e9937ae5192857942b661603",
"EndpointID": "66d74579ee50bc8289dfc58235188e262ebf707f2f0ae0ccb640524e6e9d3f22",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:02"
}
}
}
any help would be appriciated

My Docker container does not have IP address. Why?

I started a rethinkDB docker container using the command
docker pull rethinkdb:2.3
docker run --rm --name rethinkdb -v /srv/rethinkdb:/data --net host rethinkdb:2.3 rethinkdb --bind all --cache-size 8192 --no-update-check
Now the container started successfully. I did docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f288961ef376 rethinkdb:2.3 "rethinkdb --bind ..." 9 minutes ago Up 9 minutes rethinkdb
1f71722698ae sorccu/adb:latest "/sbin/tini -- adb..." 14 minutes ago Up 14 minutes adbd
Now I want to find out the IP address of this container. So I did
docker inspect --format '{{ .NetworkSettings.IPAddress }}' f288961ef376
It's returning me nothing. I couldn't find IP address for this container.
I checked if the rethinkDB configuration page is up or not by going to http://localhost:8080 and I see it's up and running.
Why doesn't this container have any IP address?
Output of docker inspect is as follows
[
{
"Id": "f288961ef376531c97d2264cb8ef3c6077a6a75107905d6a47734303adfcb117",
"Created": "2017-05-05T11:13:45.382460184Z",
"Path": "rethinkdb",
"Args": [
"--bind",
"all",
"--cache-size",
"8192",
"--no-update-check"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 8157,
"ExitCode": 0,
"Error": "",
"StartedAt": "2017-05-05T11:13:45.774035358Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:c5ed876750b40cde4725ea9eb9d8503f4d1419a2f23ac2ef8e4cc1d535e2c3a2",
"ResolvConfPath": "/var/lib/docker/containers/f288961ef376531c97d2264cb8ef3c6077a6a75107905d6a47734303adfcb117/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/f288961ef376531c97d2264cb8ef3c6077a6a75107905d6a47734303adfcb117/hostname",
"HostsPath": "/var/lib/docker/containers/f288961ef376531c97d2264cb8ef3c6077a6a75107905d6a47734303adfcb117/hosts",
"LogPath": "/var/lib/docker/containers/f288961ef376531c97d2264cb8ef3c6077a6a75107905d6a47734303adfcb117/f288961ef376531c97d2264cb8ef3c6077a6a75107905d6a47734303adfcb117-json.log",
"Name": "/rethinkdb",
"RestartCount": 0,
"Driver": "aufs",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "docker-default",
"ExecIDs": null,
"HostConfig": {
"Binds": [
"/srv/rethinkdb:/data"
],
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "host",
"PortBindings": {},
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
},
"AutoRemove": true,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "runc",
"ConsoleSize": [
0,
0
],
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": null,
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": [],
"DeviceCgroupRules": null,
"DiskQuota": 0,
"KernelMemory": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": -1,
"OomKillDisable": false,
"PidsLimit": 0,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0
},
"GraphDriver": {
"Data": null,
"Name": "aufs"
},
"Mounts": [
{
"Type": "bind",
"Source": "/srv/rethinkdb",
"Destination": "/data",
"Mode": "",
"RW": true,
"Propagation": ""
}
],
"Config": {
"Hostname": "dev-machine",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": true,
"AttachStderr": true,
"ExposedPorts": {
"28015/tcp": {},
"29015/tcp": {},
"8080/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"RETHINKDB_PACKAGE_VERSION=2.3.5~0jessie"
],
"Cmd": [
"rethinkdb",
"--bind",
"all",
"--cache-size",
"8192",
"--no-update-check"
],
"Image": "rethinkdb:2.3",
"Volumes": {
"/data": {}
},
"WorkingDir": "/data",
"Entrypoint": null,
"OnBuild": null,
"Labels": {}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "bd17bf8e1663ff18f6674a1a3a1665c4e1bf65283d358ffc97dc238ef4a79088",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {},
"SandboxKey": "/var/run/docker/netns/default",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"host": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "30b6150968580d33aae0e45f7d850b9e67ae2aa29e1bb837ca4fa74f2b0d4d42",
"EndpointID": "05e93ec514ee6694e57d344f3e4362252104347c3cc48c607708d125715ed6ec",
"Gateway": "",
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": ""
}
}
}
}
]
You are starting your container with the --net host option which means your container will run on your host network. Check here for more info. So your container will be accessible on the IP of your host.
A very basic example:
$ docker run --net=host -d jenkins
This will run jenkins on your real host network. So when you open the firewall (jenkins runs on 8080) you will access your container immediatly.
So I open the firewall:
$ sudo iptables -I INPUT 5 -p tcp -m tcp --dport 8080 -j ACCEPT
I check the real IP of my eth0 (host network) with ifconfig. (I'm doing this on a VM). It is inet 192.168.140.7. I go in my browser to 192.168.140.7:8080 and I see the jenkins. So your container has no own IP. It's running on your host network and host IP.
If you leave the --net host option, the container will be created in the default docker bridge network with range "172.17.0.0/16". Now your container will get an IP from in the range of that network. To access the container from the outside you have to map your ports on your host network (see the more info). You can do this with the -p option.
So for the jenkins example:
$ docker run -d -p 8888:8080 jenkins
When I perform a docker inspect I see:
"IPAddress": "172.17.0.4",
So my container is running in the bridge network on 172.17.0.4:8080.
Now with the -p option I'm mapping the port 8080 of my bridge network on 8888 of my host network: so host-IP:8888. Now it's accessible from the outside.
Your container ip the the same as the host. host basically says that your container uses the same network interface as the host. It is fast since there's no bridging but limited; You have to make sure that your containers do not listen to the same port to avoid conflicts.
It's better to stick with the default bridge network and specify the port that you want exposed to the host. For instance:
docker run --rm --name rethinkdb -v /srv/rethinkdb:/data -p 8080:8080 \
rethinkdb:2.3 rethinkdb --bind all --cache-size 8192 --no-update-check
btw, --net has been renamed --network in later versions of Docker.

How to access "http://localhost" from a Docker container in Windows?

I have a set of containers running in Windows 10 with Docker, this is the output of docker-compose ps:
> docker-compose ps
Name Command State Ports
--------------------------------------------------------------------------------------------------------------
db_mysql docker-entrypoint.sh mysqld Up 3306/tcp
elk /usr/bin/supervisord -n -c ... Up 0.0.0.0:81->80/tcp
php71-fpm-nginx /config/bootstrap.sh Up 443/tcp, 0.0.0.0:80->80/tcp, 0.0.0.0:9001->9001/tcp
And this is the output of docker inspect:
> docker inspect php71-fpm-nginx
[
{
...
"NetworkMode": "anotherlampdocker_default",
"PortBindings": {
"80/tcp": [
{
"HostIp": "",
"HostPort": "80"
}
],
"9001/tcp": [
{
"HostIp": "",
"HostPort": "9001"
}
]
},
...
"Mounts": [
{
"Source": "/d/Development/www",
"Destination": "/data/www",
"Mode": "rw",
"RW": true,
"Propagation": "rprivate"
},
...
"NetworkSettings": {
"Bridge": "",
"SandboxID": "b96cf4c0f2c17d65659c31982b9200a79cca6f1c214770d31938204c493a6720",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"443/tcp": null,
"80/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "80"
}
],
"9001/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "9001"
}
]
},
...
"Networks": {
"anotherlampdocker_default": {
"IPAMConfig": null,
"Links": [
"db_mysql:db",
"db_mysql:db_mysql"
],
"Aliases": [
"php-fpm",
"248e8c254eee"
],
"NetworkID": "de1e10b63e6e5050809af59ac4d26b7cb691afd5805d1cf7f0492c702814f34d",
"EndpointID": "ccec71967c6100c5a9f3ad82d82bbb2a371f77e12c493bf05bfd15f2d188ce00",
"Gateway": "172.18.0.1",
"IPAddress": "172.18.0.3",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:12:00:03"
}
}
}
}
]
I am trying to access http://localhost but I can't. I've tried also using the container IP meaning http://172.18.0.3 and doesn't work either.
When I say I can't it means the following message:
This site can’t be reached
172.18.0.3 took too long to respond.
The same container works perfectly in Linux.
This is the content of c:\Windows\System32\drivers\etc\hosts file:
# localhost name resolution is handled within DNS itself.
127.0.0.1 localhost
The ports from the container are mapped to the host in the docker-compose.yml file:
services:
php-fpm:
container_name: "php71-fpm-nginx"
build: php-fpm
ports:
- 80:80
- 9001:9001
environment:
PHP_ERROR_REPORTING: 'E_ALL & ~E_DEPRECATED & ~E_NOTICE'
STATUS_PAGE_ALLOWED_IP: '127.0.0.1'
volumes:
- D:\Development\www\:/data/www
What I am missing here?
You can get the docker machine IP and access the application:
1. Using command docker-machine : docker-machine ip
2.or By login to the docker image which is created when you start the docker and getting the eth1 ip
Then try : [docker-machine ip]:[port]
Try login to the php's container and check if the httpd process is running.
Use docker-compose up without -d should help you to see the log from container or use docker-compose logs -f -t after docker-compose up -d

Resources