# Use multiple Docker containers without exposing ports

**URL:** https://meta.discourse.org/t/use-multiple-docker-containers-without-exposing-ports/22283
**Category:** Sysadmins
**Tags:** docker, how-to, advanced-setup
**Created:** [November 18, 2014, 9:43pm UTC](https://meta.discourse.org/t/use-multiple-docker-containers-without-exposing-ports/22283 "2014-11-18T21:43:13Z")
**Posts on this page:** 1
**Showing post:** 1

<div class="post-metadata">

### Author: ![jspdng](https://avatars.discourse-cdn.com/v4/letter/j/90ced4/32.png) [@jspdng](https://meta.discourse.org/u/jspdng)
#### Post date: [November 18, 2014, 9:43pm UTC](https://meta.discourse.org/t/use-multiple-docker-containers-without-exposing-ports/22283/1 "2014-11-18T21:43:14Z")

</div>

> ⚠ This is an advanced setup. Don’t follow this unless you are experienced with Linux server administration and Docker.

Hello everyone!

If you don’t want to mess with the firewall rules and security of your server, you can configure your Docker multiple container setup with just links and **no** exposed ports!

This way you can share your data container (postgres/redis) with other containers without exposing it to the internet.

* * *

## How to

1. Edit your `data.yml` file commenting all the `expose` section:

2. Edit your `web_only.yml` file uncommenting the `links` section:

3. The trick! Also on `web_only.yml` file, use your data container’s name to connect to the database:

* * *

## The Docker Magic

As explained on [Docker Container Linking](https://docs.docker.com/userguide/dockerlinks/#docker-container-linking) documentation, when you `--link` containers:

> Docker adds a host entry for the source container to the /etc/hosts file

So now the containers can communicate locally! Also:

> If you restart the source container, the linked containers /etc/hosts files will be automatically updated with the source container’s new IP address, allowing linked communication to continue.

---

_[View the full topic](https://meta.discourse.org/t/use-multiple-docker-containers-without-exposing-ports/22283)._
