I run: docker run -p "9999:80" nginx and attempt to access the web server using the following address: 172.17.0.2:9999. I got this IP from docker inspect [container_id]:
"NetworkSettings": {
"Bridge": "",
"SandboxID": "877eb750a0f35037f0b9dff2b6bd95f7dd4aaf80ae0ed8cf65e20ad8aeb85132",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"80/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "9999"
}
]
},
"SandboxKey": "/var/run/docker/netns/877eb750a0f3",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "2599dc8c2311725e9816fc30e60a86550cb42887871a921365e3df866427464e",
"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": "ffc037f862047b118824b8d322aab771ba75a009881959461be577ffebb42a80",
"EndpointID": "2599dc8c2311725e9816fc30e60a86550cb42887871a921365e3df866427464e",
"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
}
}
}
But this doesn't work as expected. If I ping 172.17.0.2 from the host I get no response.
Any ideas what's going wrong? It's so much hassle with docker-toolbox because my version of Windows 10 isn't supported by docker.
Since you launched the container with docker run -p 9999:80, you can reach it on the VM's IP address on the public port 9999. docker-machine ip will tell you that IP address (but it is usually 192.168.99.100). So try http://192.168.99.100:9999/ as a URL to reach the container.
The container-internal IP addresses aren't especially useful. One significant problem with them is that they can't be reached from other hosts. In the case of a Docker Toolbox environment, everything Docker-related actually runs inside a virtual machine, and your host system counts as "other hosts" for this. Also note that if you do have occasion to use it (or more often use inter-container DNS for one container to reach another by its docker run --name) you need the port the server is listening on inside the container, not the published port: from another container you might use http://nginx_container_name:80/.
Related
I have 'docker desktop' installed on my windows 10.
so, I pulled in Jenkins image from docker hub and then run the commands:
docker pull jenkins/jenkins
docker volume create jenkins_home
docker run --name jenkins -p 8080:8000 -p 50000:50000 -v C:/Users/myusername/Documents/jenkins_home:/var/jenkins_home jenkins/jenkins
On console, everything was ok, and get the password for the admin user.
So after that I run
docker start jenkins
and then
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
36683f39dd31 jenkins/jenkins "/sbin/tini -- /usr/…" 6 minutes ago Up 2 minutes 8080/tcp, 0.0.0.0:50000->50000/tcp, 0.0.0.0:8080->8000/tcp jenkins
Now, I need to log into http://localhost:8080/ port to view the Jenkins web app. But did not bring up Jenkins app. I also tried using docker inspect to get the container's ip, but port 8080 didn't work on those ips as well.
"NetworkSettings": {
"Bridge": "",
"SandboxID": "19504b4695ca4dfc9c4af41c9a7ef90115004af07d0099ffed33f4838155cddb",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"50000/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "50000"
}
],
"8000/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "8080"
}
],
"8080/tcp": null
},
"SandboxKey": "/var/run/docker/netns/19504b4695ca",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "f1938dad37524b58d3146f8bfffa4964687d1946ab97b3ae7f0105ced3f64ddf",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:02",
"Networks": {
"Aliases": null,
"NetworkID": "b285258a51bc4877fa9ff8a1928eced061f61a4f92f54a5aa756a118e0f1cb7b",
"EndpointID": "f1938dad37524b58d3146f8bfffa4964687d1946ab97b3ae7f0105ced3f64ddf",
"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
}
}
NOTE: Before running jenkins, I made sure the port wasn't busy.
netstat -aon | findstr 8080
After kenkins running, the command shows me
TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 25076
TCP [::]:8080 [::]:0 LISTENING 25076
If I find the process to use this port, I got this
tasklist | findstr 25076
com.docker.backend.exe 25076 Console 2 22.664 K
so, Which ip address do I use to see the Jenkins app that is running in the container? and why the localhost on port 8080 doen't work ?
First to be clear, my docker container has an IP address under NetworkSettings.Networks.bridge. That IP is 172.17.0.2
However I cannot access the container via http://172.17.0.2:3000/ after running it with docker run -p 3000:3000 node:8.10.0
My research shows its rough working with docker locally on windows. In following this short guide: https://blog.sixeyed.com/published-ports-on-windows-containers-dont-do-loopback/
I come across using the network NAT IP address. I see this recommended a few places. But that section of my docker inspect does not exist at all.
It returns:
"NetworkSettings": {
"Bridge": "",
"SandboxID": "0c81d8f7ce5bcba70ec0487bbfe91bc6f221e29d9378c33708fac78d0ae47d3e",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"3000/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "3000"
}
]
},
"SandboxKey": "/var/run/docker/netns/0c81d8f7ce5b",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "bbe5f42a5b53c001bd3c2852bc6b22976fb9bab2afcb88b30f6660d7662f526f",
"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": "0af66a62bc57ce25491c82f5a13d947ca79f5a879f3c1a6db40a90233eeb04f8",
"EndpointID": "bbe5f42a5b53c001bd3c2852bc6b22976fb9bab2afcb88b30f6660d7662f526f",
"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
}
}
As you can see the NAT section is missing entirely. I cant find anything online that mentions why or how to resolve. I was hoping it missing would be a good thing and make it easier to connect. Alas it does not. Any help is appreciated. Here is the dockerfile:
FROM node:8.10.0
WORKDIR /app
COPY package.json /app
RUN npm install
COPY . /app
CMD ["./node_modules/gulp/bin/gulp.js", "assets"]
CMD [ "node", "app.js" ]
EXPOSE 3000
That's a known bug under docker windows. It is fixed in 19.03. So try updating your docker engine.
I need to enable both IPv4/IPv6 dualstack support for my docker containers. My docker compose file is version 3. By default IPv4 is enabled but how do I enable IPv6 for my docker containers/network?
I have already tried to update the docker daemon by updating the daemon.json and I know the updates are being recognised because Docker will not start if there are errors in the file. I have restarted Docker (not just my containers) after making the changes, but still no IPv6 addresses for my containers.
I have discovered that enable_ipv6: true in the docker compose file is not valid for version 3 or greater and I would not like to downgrade by file version.
My updated daemon.json:
{
"ipv6": true,
"fixed-cidr-v6": "2001:db8:1::/64"
}
When I inspect my containers, after making changes to the daemon.json, with docker inspect {id} I see the following:
"NetworkSettings": {
"Bridge": "",
"SandboxID": "df737362d15722fc1b0501ac256ba371417fe513dede807f2a17bd0524630a31",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"9000/tcp": null
},
"SandboxKey": "/var/run/docker/netns/df737362d157",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"healixportal_default": {
"IPAMConfig": null,
"Links": null,
"Aliases": [
"php-fpm",
"9b8a7aee156b"
],
"NetworkID": "5523ae0a4a936b47f212f0e301b64cbbad1f279a33107ed1f624e28d2df96c66",
"EndpointID": "880e13b64bec3fc84ae5a0abb5054bda66d5f439da6853f3538eb33be14b256b",
"Gateway": "172.18.0.1",
"IPAddress": "172.18.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:12:00:02",
"DriverOpts": null
}
}
}
So there is still no IPv6 address assigned to my container...
According to this issue for the compose repo IPv6 is not supported like that yet, but there is a workaround that might do the trick for you:
You must comment enable_ipv6: true, and leave all the others parameters as the documentation says.
After running:
$ sudo docker-compose build
Then execute:
$ docker network create --driver bridge --ipv6 --subnet fd15:555::/64 --subnet 172.16.238.0/24 containerName-dockerfile_app_net --attachable
$ sudo docker-compose up -d
I have the nginx running in docker(Docker for mac, using docker-compose), here is the "Networks" section of docker inspect.
{
"Networks": {
"laradock_backend": {
"IPAMConfig": null,
"Links": null,
"Aliases": [
"c189cabxfdf9",
"nginx"
],
"NetworkID": "f4f8d8ff07ae90d5758644968d96f2g653fc5188c895f19c2d08de92c46cc075",
"EndpointID": "f8c6d5a8b061c75c44c2e078a65928a9b45dd91833fc05x7f249c64a180e84a1",
"Gateway": "172.21.0.1",
"IPAddress": "172.21.0.4",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:02:fc:15:10:05",
"DriverOpts": null
},
"laradock_frontend": {
"IPAMConfig": null,
"Links": null,
"Aliases": [
"c189cab4ddg1",
"nginx"
],
"NetworkID": "7b410b1bd764617a3f6146862307f886681e57aaxf057e4308f1236e1558ffcb",
"EndpointID": "0caa62bc5bbx600a5b1f260ebg11014e05394671ca347f818bfx819f43f7011e",
"Gateway": "172.22.0.1",
"IPAddress": "172.22.0.3",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "01:41:af:16:00:03",
"DriverOpts": null
}
}
}
I'm not an expert on computer networking. But I use docker very frequently, I just want to understand a little better about what's happening whenever I connect to the docker container through my host machine (localhost).
Where I found each network has a "Gateway" there.
I can't find such interfaces on my host machine. Where does the "Gateway" sits? Why we need such a thing?
Any simple charts would be helpful…
Thanks.
The gateway is the device that connects the network to the outside world. When a packet is sent to a destination that is not in the same network, the packet is sent to the gateway, which knows how to sent it to the next router and so on, until the packet receive at the destination.
In this case, this gateway device is virtual and its part of a bridge between the container and the host physical interface. This emulation is needed in order to permit the software that runs in the container to run as it would be on the host. It also separate the network of the container to the network of the host (the separation is the motive for which you use docker).
I have installed docker-toolbox v1.12 locally on a Windows 8.1 laptop.
As suggested here I have run docker run -d --name exhibitor netflixoss/exhibitor:1.5.2. This has pulled all the images in my Docker VM "home". docker inspect <<container-id>> (container id obtained from docker ps command) reveals my Network Settings as below.
"NetworkSettings": {
"Bridge": "",
"SandboxID": "c1a16c1704f76b2e2a35b2ae6a18780aaedac078cceb005b419cafb405b1e3b2",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"2181/tcp": null,
"2888/tcp": null,
"3888/tcp": null,
"8080/tcp": null
},
"SandboxKey": "/var/run/docker/netns/c1a16c1704f7",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "3e19d6c6eeb2e7c9dbb9b357ac4ecc9515bdf391df6688f17420bb9443ce3d22",
"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": "85b5af82cb891978b6d3272f622c747fa68546d0401a24e85c9d42f7644ea2d4",
"EndpointID": "3e19d6c6eeb2e7c9dbb9b357ac4ecc9515bdf391df6688f17420bb9443ce3d22",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:02"
}
}
}
I'm trying to invoke the running Docker container from Windows host using "http://172.17.0.2:8080/exhibitor/v1/ui/index.html". But that doesn't seem to work. docker ps suggests the container is up
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
NAMES
1a849df14320 netflixoss/exhibitor:1.5.2 "java -jar exhibitor-" About an hour ago Up About an hour 2181/tcp, 2888/tcp, 3888/tcp, 8080/t
cp exhibitor
Also I can connect to the container using docker attach 1a849df14320 and see the following log entries time-to-time
INFO com.netflix.exhibitor.core.activity.ActivityLog Cleanup task completed [pool-2-thread-93]
I'm a complete newbie with Docker.
You have not exposed the port to the host.
docker ps -a should give output similar to:
0.0.0.0:1234->9876/tcp, 0.0.0.0:4321->7890/tcp
This shows port 1234 on the host is mapped to 9876 in the container.
Your docker ps output has no port mappings. You should do:
docker run .......... -p 8080:8080
You can always use the -P flag too (if you expose the port in the Dockerfile) but the above solution is the quickest.