简体   繁体   中英

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 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?

根据docker文档 ,推荐的指定端口映射的方法是字符串声明,特别是当容器端口小于60时。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM