Martin Delille
Martin Delille

Reputation: 11770

Changing port in docker-compose.yml

I'm learning how to use docker-compose following the official documentation: https://docs.docker.com/compose/gettingstarted/

When browsing to http://myserver.com:5000 I have the expected result:

Hello World! I have been seen 1 times.

I would like to change the listening port to 5001 modifying the docker-compose.yml file as follow:

version: '2'
  services:
    web:
      build: .
      ports:
       - "5001:5001"
      volumes:
       - .:/code
      depends_on:
       - redis
    redis:
      image: redis

Unfortunately, after stop and removing the container (with 'docker-compose down') and start it again (with 'docker-compose up -d'), the connection to http://myserver.com:5001 is refused.

Any idea?

Upvotes: 18

Views: 54323

Answers (1)

Kim T
Kim T

Reputation: 6416

You should change the external port only (the first port number in xxxx:xxxx which maps to HOST:CONTAINER)

version: '2'
  services:
    web:
      build: .
      ports:
       - "5001:5000"
      volumes:
       - .:/code
      depends_on:
       - redis
    redis:
      image: redis

Link to documentation: https://docs.docker.com/compose/compose-file/compose-file-v3/#ports

Upvotes: 29

Related Questions