I am trying to expose port 3000 of my container to the host. This is the command I am using:
docker run -ti --expose=3000 -p 3000:3000 dockerName
On the PORTS
section of docker ps
I see 0.0.0.0:3000->3000/tcp
.
When I try to connect to a simple NodeJS server on that port I get Unable to connect
. I am running Docker 18.03.0-ce and the latest version of NodeJS.
I try to connect through localhost (127.0.0.1) IP, the internal container IP (172.17.0.1), the IP issued by the host OS (172.17.0.1) and the host IP all without success. I have also completely disabled the firewall on the host OS.
Here is the NodeJS code, which works fine on the host:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(3000, "127.0.0.1");
console.log('Server running at http://127.0.0.1:3000/');
Is there any way to get this to work inside the container and connect to it through the host OS?