I've started using docker for dev, with the following setup:
- Host machine - ubuntu server.
- Docker container - webapp w/ tomcat server (using https).
As far as host-container access goes - everything works fine. However, I can't manage to access the container's webapp from a remote machine (though still within the same network).
When running
docker port <container-id> 443
output is as expected, so docker's port binding seems fine.
172.16.*.*:<random-port>
Any ideas?
Thanks!
If your container was built with a Dockerfile that has an
EXPOSE
statement, e.g.EXPOSE 443
, then you can start the container with the-P
option (as in "publish" or "public"). The port will be made available to connections from remote machines:If you didn't use a Dockerfile, or if it didn't have an
EXPOSE
statement (it should!), then you can also do an explicit port mapping:In both cases, the result will be a publicly-accessible port:
Last but not least, you can force the port number if you need to:
In that case, connecting to your Docker host IP address on port 8442 will reach the container.
I figured out what I missed, so here's a simple flow for accessing docker containers webapps from remote machines:
Step #1 : Bind physical host ports (e.g. 22, 443, 80, ...) to container's virtual ports. possible syntax:
(see docker docs for port redirection with all options)
Step #2 : Redirect host's physical port to container's allocated virtual port. possible (linux) syntax:
That should cover the basic use case.
Good luck!
There are some alternatives of how to access docker containers from an external device (in the same network), check out this post for more information http://blog.nunes.io/2015/05/02/how-to-access-docker-containers-from-external-devices.html
Correct me if I'm wrong but as far as I'm aware docker host creates a private network for it's containers which is inaccessible from the outside. That said your best bet would probably be to access the container at {host_IP}:{mapped_port}.