Change db containers ports

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

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

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.

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.

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.

It’s not all that complicated though :slightly_smiling_face: - it’s whatever one would type to run the server directly. See the 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!

As you can see in the original postgres dockerfile here, 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)

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 :hugs: - this is a miniscule problem with a perfectly easy solution.