StephaneM
StephaneM

Reputation: 4899

docker-compose: publish multiple ports

I'm trying to publish 2 ports of a simple docker container to make some tests.

Here are the steps to reproduce the issue.

My simple Dockerfile:

FROM bash:4 
RUN echo ok

Built using docker build . -t essai

My first version for the docker-compose.yml file, this one works:

version: '3'
services:
  essai:
    image: essai 
    ports:
      - 25432:5432

But when I try to publish a second port like this:

version: '3'
services:
  essai:
    image: essai 
    ports:
      - 25022:22
      - 25432:5432

I get this strange error message:

$ docker-compose up Creating network "sandbox_default" with the default driver Creating sandbox_essai_1 ... Creating sandbox_essai_1 ... error

ERROR: for sandbox_essai_1 Cannot create container for service essai: invalid port specification: "1501342"

ERROR: for essai Cannot create container for service essai: invalid port specification: "1501342" ERROR: Encountered errors while bringing up the project.

Where does it find the port 1501342?

Funny thing is when I write my docker-compose like this:

version: '3'
services:
  essai:
    image: essai 
    ports:
      - "25022:22"
      - 25432:5432

It works.

What's the magic with these double quotes and the port number coming out of nowhere?

Upvotes: 11

Views: 42892

Answers (1)

andolsi zied
andolsi zied

Reputation: 3791

According to the docker documentation, the recommended way to specify port mapping is string declaration specially when a container port lower than 60.

Upvotes: 11

Related Questions