Docker Community Forums

Share and learn in the Docker community.

Visit container from device within the same LAN


(Yishengyang) #1

I have a program running inside a docker container and I expose the port 8888. However, when I try to connect the program from a device (in the same LAN as host machine but not the host machine) it failed.
Here is my docker file

FROM golang:1.10.1

RUN go build -buildmode=plugin -o plugin.so plugin.go

EXPOSE 8666:8888

And I start the container with

docker run -it -P --network host plugin:v0.3 bash

and run

go run program.go

in bash.
It says

2018/07/30 01:51:43 listening port 8888

But I cannot connect to the port from other device(which is in the same LAN as host machine but not the host machine)

then I tried

docker ps -a

It looks different in that the ports column are empty(Usually there should be a mapping?)

enter image description here

Docker version 18.06.0-ce, build 0ffa825

docker network inspect host

[
{
“Name”: “host”,
“Id”: “256062b5f249cfcefc2fbda16919fd7e495c28f17fec1df55a8d085a93ccc94c”,
“Created”: “2018-07-05T05:27:09.039136061Z”,
“Scope”: “local”,
“Driver”: “host”,
“EnableIPv6”: false,
“IPAM”: {
“Driver”: “default”,
“Options”: null,
“Config”: []
},
“Internal”: false,
“Attachable”: false,
“Ingress”: false,
“ConfigFrom”: {
“Network”: “”
},
“ConfigOnly”: false,
“Containers”: {
“bb80a7542fd2dd1a4985a7cbbfe46b43977147eabc2b22da2d2271c6782d54c0”: {
“Name”: “quizzical_saha”,
“EndpointID”: “cbf550879b288d4988909de486d33b3860735c81a46f998b107bbb730cfd0004”,
“MacAddress”: “”,
“IPv4Address”: “”,
“IPv6Address”: “”
}
},
“Options”: {},
“Labels”: {}
}
]


(Martin Terp) #2

Hi :slight_smile:

Its because you run it with: --network host, then it wont “open” ports, but will run the service as if it was running on the host.
Can you connect to port 8888 from the host?