Low Orbit Flux Logo 2 F

Docker How To Access Port On Host From Container

We are going to show you how to access a port on the local host from within a Docker container.

If you are using default network settings this should be pretty straight forward. You just need the IP of your host system.

Lookup your IP with either of these commands:



ip a
ifconfig -a

Lets say your IP is 192.168.3.246 for example. If you have a web server running on your host system ( on port 80 ) and you want to access that from within a container. You can just directly access it using the IP and port. Here are the steps as an example.

Attach to the container:



docker attach test-container1

Access the port on the host system:



wget 192.168.3.246:80

Note that for the above example you would also need to have wget installed. This is just an example and you will probably be trying to acess some other port for some other application.

In case you want to install wget, you would use these commands on an Ubuntu/Debian system:



apt update
apt install wget -y