<p>A container can access services on the host network without any additional configuration.</p>
<p>To provide your host -- or other hosts on your network -- access to containerized services, you would typically publish a container port on the host. E.g., if you have a frontend proxy and then a number of internal backend containers, your proxy container would publish a port to the host...</p>
<pre><code>docker run --name frontend -p 8080:80 ...
</code></pre>
<p>...so that you can access the proxy at <code>http://&lt;some_address_of_the_host&gt;:8080</code>.</p>
<p>See the documentation <a href="https://docs.docker.com/guides/docker-concepts/running-containers/publishing-ports/" rel="nofollow noreferrer">here</a> for more information and examples.</p>

CC BY-SA 4.0
2024-07-30T02:19:46.737Z
So does the -p argument override the argument to have the container run on the internal network?
maxical
CC BY-SA 4.0
2024-07-30T02:24:10.447Z
No. It sets up port forwarding from the host port to the container port. The container continues to run on the internal container network.
larsks
CC BY-SA 4.0
2024-07-30T02:26:08.223Z
Ok, so the internal network is still up except for the ports listed in the -p command which go directly to host?
maxical
CC BY-SA 4.0
2024-07-30T02:27:45.973Z
No. Nothing about the container changes. Your application continue to listen on their ports on the internal network. Port publishing sets up port **forwarding** on the host -- so that connections to the specified host port will be forwarded/proxied to the appropriate container port (generally through the application of some netfilter rules by the docker daemon).
larsks
CC BY-SA 4.0
2024-07-29T18:30:43.313Z
2024-07-29T18:30:43.313Z
larsks
<p>I am confused on how you set up a docker container so that you can access both your host network and an internal network of containers?</p>
<p>Ex let's say you want container 1 to act as a proxy between internal containers network and outside.</p>
<p>How is this done?</p>

<docker><networking><network>
Docker container to accessing host and internal network
maxical
# Docker container to accessing host and internal network

(Asked by: username_0 on 2024-07-29)

I am confused on how you set up a docker container so that you can access both your host network and an internal network of containers?

Ex let's say you want container 1 to act as a proxy between internal containers network and outside.

How is this done?

**Tags:** docker, networking, network


---

## 1 answers

### Answer by username_1 on 2024-07-29. Score: 1 | Accepted answer

A container can access services on the host network without any additional configuration.
To provide your host -- or other hosts on your network -- access to containerized services, you would typically publish a container port on the host. E.g., if you have a frontend proxy and then a number of internal backend containers, your proxy container would publish a port to the host...
docker run --name frontend -p 8080:80 ...

...so that you can access the proxy at http://:8080.
See the documentation here for more information and examples.

> **Comments:**
> **username_0**: So does the -p argument override the argument to have the container run on the internal network?  
> **username_1**: No. It sets up port forwarding from the host port to the container port. The container continues to run on the internal container network.  
> **username_0**: Ok, so the internal network is still up except for the ports listed in the -p command which go directly to host?  
> **username_1**: No. Nothing about the container changes. Your application continue to listen on their ports on the internal network. Port publishing sets up port **forwarding** on the host -- so that connections to the specified host port will be forwarded/proxied to the appropriate container port (generally through the application of some netfilter rules by the docker daemon).  

---

