# Change db containers ports

**URL:** <https://discuss.circleci.com/t/change-db-containers-ports/30234>\
**Category:** Databases\
**Created:** [May 6, 2019, 1:10pm UTC](https://discuss.circleci.com/t/change-db-containers-ports/30234 "2019-05-06T13:10:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![NotSoShaby](https://avatars.discourse-cdn.com/v4/letter/n/f1d935/32.png) [@NotSoShaby](https://discuss.circleci.com/u/NotSoShaby)\
**Post date:** [May 6, 2019, 1:10pm UTC](https://discuss.circleci.com/t/change-db-containers-ports/30234/1 "2019-05-06T13:10:16Z")

</div>

Im are trying to set up our tests and I noticed that there is no `ports` command that can be passed to a docker image.

This sounds really weird because it sounds like a very basic feature.

in any case, how can I change my postgres ports in the config (attached is what i have)?

```
version: 2

jobs:
  test:
    docker:
      - image: circleci/python:3.6.5-stretch
        environment:
          ENV: test
          CIRCLECI_RUN: true
      - image: circleci/postgres:9.6-alpine
        environment:
          POSTGRES_USER: test
          POSTGRES_DB: test
```

---

<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:** [May 6, 2019, 1:23pm UTC](https://discuss.circleci.com/t/change-db-containers-ports/30234/2 "2019-05-06T13:23:08Z")

</div>

> [@NotSoShaby](#):
>
> [A port specification] sounds like a very basic feature.

I would guess that it is not provided because port opening is not a feature of an operating system or a container, it is a feature of a program.

So if you want Postgres to open a non-standard port, then tell Postgres. I believe there is a `command` key you can use to specify the server’s start-up script - see the CircleCI docs for that. Then, find out a server start command, and then modify it to add a port amendment - I would guess one can do this with the Postgres server binary.

Out of interest, why do you want to do this? Are you wanting to run two Postgres instances side-by-side, and want to avoid a port conflict? If not, it may just be easier to change the port in your system under test.

---

<div class="post-metadata">

**Author:** ![NotSoShaby](https://avatars.discourse-cdn.com/v4/letter/n/f1d935/32.png) [@NotSoShaby](https://discuss.circleci.com/u/NotSoShaby)\
**Post date:** [May 6, 2019, 2:50pm UTC](https://discuss.circleci.com/t/change-db-containers-ports/30234/3 "2019-05-06T14:50:33Z")

</div>

but this is an option that I can pass to docker on a `docker run` command, and because circleci is running that command, i would expect it to have the option to pass these params to the `docker run` command. otherwise im not in control of my containers.

We use different ports because our tests use a different db then our system, when we run both locally, we must have these dbs on different ports, so tests are using a custom port.

going to the extend of Postgres server binary feels a little like an overkill for something that is a simple docker param.

---

<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:** [May 6, 2019, 3:00pm UTC](https://discuss.circleci.com/t/change-db-containers-ports/30234/4 "2019-05-06T15:00:57Z")

</div>

> [@NotSoShaby](#):
>
> this is an option that I can pass to docker on a `docker run` command

It is, but the remote container environment is rather more complicated than that. You could propose a feature request on the Ideas page. It would have to specify two ports - a local one and a remote one - in order to account for servers that open more than one port.

> [@NotSoShaby](#):
>
> going to the [extent] of Postgres server binary feels a little like an overkill

It’s not all that complicated though 🙂 - it’s whatever one would type to run the server directly. See the [full example](https://circleci.com/docs/2.0/configuration-reference/#full-example) - the Mongo one is `[mongod, --smallfiles]`, which presumably would also allow a port config switch. I don’t know the Postgres one, but I am confident you can research it!

---

<div class="post-metadata">

**Author:** ![NotSoShaby](https://avatars.discourse-cdn.com/v4/letter/n/f1d935/32.png) [@NotSoShaby](https://discuss.circleci.com/u/NotSoShaby)\
**Post date:** [May 7, 2019, 10:04am UTC](https://discuss.circleci.com/t/change-db-containers-ports/30234/5 "2019-05-07T10:04:34Z")

</div>

As you can see in the original postgres dockerfile [here](https://github.com/docker-library/postgres/blob/master/9.6/Dockerfile), the exporting of the port is happening before the command, and overriding the command will not help with that.

On a side-note - this is really odd and a deal breaker for my company in using CircleCI, as we need to have the ability to control our resources (im currently leading a POC for the tests and if it goes well, then we would want to move our whole deployment the - which isnt the case now)

---

<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:** [May 7, 2019, 3:56pm UTC](https://discuss.circleci.com/t/change-db-containers-ports/30234/6 "2019-05-07T15:56:44Z")

</div>

> [@NotSoShaby](#):
>
> the exporting of the port is happening before the command

As I understand it, the `EXPOSE` directive is effectively documentation, and does not have an effect on your runtimes - you still need to publish ports. To be clear, it can affect the `-P` switch (publish all) but there is no need to use that, since you can use `-p`.

(And I think `EXPOSE` is discouraged anyway, as there is no way to remove it or change it from downstream images - exactly the problem you are bumping into).

There are plenty of reasons to reject a CI system, but don’t die on this hill 🤗 - this is a miniscule problem with a perfectly easy solution.
