Veiga
Veiga

Reputation: 111

Add new port in running docker compose

I am trying to add a SSL certificate to a wordpress container but the default compose configuration only redirects port 80.

How can I add a new port in the running container? I tried to modify the docker-compose.yml file and restart the container but this doesn't solve the problem.

Thank you.

Upvotes: 8

Views: 11458

Answers (5)

harleygolfguy
harleygolfguy

Reputation: 805

After you add the new port to the docker-compose file, what I did that works is:

  1. Stop the container

    docker-compose stop <service name>

  2. Run the docker-compose up command (NOTE: docker-compose start did not work)

    docker-compose up -d

According to the documentation the 'docker-compose' command:

Builds, (re)creates, starts, and attaches to containers for a service ... Unless they are already running

That started up the stopped service, WITH the exposed ports I had configured.

Upvotes: 1

SND-KNN
SND-KNN

Reputation: 410

You should re-create container, when listening new port, like this

docker-compose up -d --force-recreate {CONTAINER}

Upvotes: 15

Mazel Tov
Mazel Tov

Reputation: 2182

you just add the new port in the port section of the docker-compose.yml and then you must do

docker-compose up -d

because it will read the .yml file again and recreate the container. If you do just restart it will not read the new config from the .yml and just restart the same container.

Upvotes: 0

Alitlili
Alitlili

Reputation: 66

Expose ports.

Either specify both ports (HOST:CONTAINER), or just the container port (an ephemeral host port is chosen).

Note: When mapping ports in the HOST:CONTAINER format, you may experience erroneous results when using a container port lower than 60, because YAML parses numbers in the format xx:yy as a base-60 value. For this reason, we recommend always explicitly specifying your port mappings as strings.

ports: - "3000" - "3000-3005" - "8000:8000" - "9090-9091:8080-8081" - "49100:22" - "127.0.0.1:8001:8001" - "127.0.0.1:5000-5010:5000-5010" - "6060:6060/udp" https://docs.docker.com/compose/compose-file/#pid

Upvotes: 1

Have you tried like in this example: https://docs.docker.com/compose/compose-file/#ports

Should work like this:

my-services:
    ports:
        - "80:80"
        - "443:443"

Upvotes: 0

Related Questions