Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I expose ports on Heroku with a Dockerfile?

Tags:

docker

heroku

I am trying to deploy a Docker image on Heroku and am trying to understand how to expose multiple ports. Here is the Docker command that I am trying to run in the Heroku deploy:

docker run \
    -p 2222:22 \
    -p 33306:3306 \
    -p 27017:27017 \
    -p 28015:28015 \
    -p 29015:29015 \
    -p 8080:8080 \
    test/db-migration

How do I do this in Heroku?

like image 566
jhamm Avatar asked Jun 14 '17 14:06

jhamm


People also ask

Can you publish a port in a Dockerfile?

You can do this in the following ways: Add an EXPOSE instruction in the Dockerfile. Use the –expose flag at runtime to expose a port. Use the -p flag or -P flag in the Docker run string to publish a port.

Can we expose 2 ports in Dockerfile?

The above command opens two random ports in the host computer and maps them with ports 8080 and 8081 of the Docker container. It behaves the same way if we expose a range of ports. This way, we also keep control of which ports of the container opens up to the outside.

How do I expose Docker container ports?

There are several ways to do this: you can expose a port via the --expose flag at runtime, or include an EXPOSE instruction in the Dockerfile. You can also publish ports by using the -p or -P flags in the Docker run string. There's also container linking via --link .


1 Answers

You can't - you should use the $PORT environment variable which will be randomly assigned and then mapped to port 80 by the Heroku routers. Also, only http requests are accepted. See https://devcenter.heroku.com/articles/container-registry-and-runtime#dockerfile-commands-and-runtime for more details.

like image 191
John Beynon Avatar answered Sep 22 '22 04:09

John Beynon