# Support for Docker port forwarding

**URL:** <https://discuss.circleci.com/t/support-for-docker-port-forwarding/25424>\
**Category:** Build Environment\
**Tags:** docker, circle-yml\
**Created:** [September 26, 2018, 7:14pm UTC](https://discuss.circleci.com/t/support-for-docker-port-forwarding/25424 "2018-09-26T19:14:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![darwinyip](https://avatars.discourse-cdn.com/v4/letter/d/54ee81/32.png) [@darwinyip](https://discuss.circleci.com/u/darwinyip)\
**Post date:** [September 26, 2018, 7:14pm UTC](https://discuss.circleci.com/t/support-for-docker-port-forwarding/25424/1 "2018-09-26T19:14:13Z")

</div>

Allow for port forwarding when using docker executor. This is handy when needing to setup multiple docker containers that use the same port.

---

<div class="post-metadata">

**Author:** ![halfer](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/halfer/32/9083_2.png) [@halfer](https://discuss.circleci.com/u/halfer)\
**Post date:** [September 26, 2018, 8:37pm UTC](https://discuss.circleci.com/t/support-for-docker-port-forwarding/25424/2 "2018-09-26T20:37:12Z")

</div>

Most servers allow you to reset the listening port using a parameter switch, and you can pass a `command` to your secondary containers already. What image/server are you wanting to run multiples of?

---

<div class="post-metadata">

**Author:** ![darwinyip](https://avatars.discourse-cdn.com/v4/letter/d/54ee81/32.png) [@darwinyip](https://discuss.circleci.com/u/darwinyip)\
**Post date:** [September 26, 2018, 10:06pm UTC](https://discuss.circleci.com/t/support-for-docker-port-forwarding/25424/3 "2018-09-26T22:06:31Z")

</div>

How can I use `command` to do that?  
Below is an example of what I wish to accomplish, granted I know there is no `port` attribute.  
All 3 apps run on port 80 which for the tests I want to forward to some other port.

```auto
docker:
  - image: app1
    name: app1
    port: 80:8080
  - image: app2
    name: app2
    port: 80:8081
  - image: app3
    name: app3
    port: 80:8082
```

---

<div class="post-metadata">

**Author:** ![halfer](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/halfer/32/9083_2.png) [@halfer](https://discuss.circleci.com/u/halfer)\
**Post date:** [September 26, 2018, 10:11pm UTC](https://discuss.circleci.com/t/support-for-docker-port-forwarding/25424/4 "2018-09-26T22:11:10Z")

</div>

There is no (documented) `port` key. You need a `command`, as I said - [see the reference here](https://circleci.com/docs/2.0/configuration-reference/#docker--machine--macosexecutor).

Your apps will also need to be able to accept a switch on the command line. For example, `command: /path/to/app1 --port 8081` would launch this binary, and you’d have to modify the binary to accept the `--port` switch. The server would then connect on `localhost:8081`, and CircleCI would then work its automatic networking magic to make that available to the primary build container.

You cannot publish ports to the local environment though, as per your syntax `80:8081`. That requires Docker to be in privileged mode, and that would not be safe to run in a shared CI environment. Use the command approach instead.

Good luck!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/circleci/original/3X/5/1/511608acda8e85906e15909b57bd0a46c1dbe291.png) [@system](https://discuss.circleci.com/u/system)\
**Post date:** [December 25, 2018, 10:11pm UTC](https://discuss.circleci.com/t/support-for-docker-port-forwarding/25424/5 "2018-12-25T22:11:15Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
