I have port 4000 exposed in the Docker container and have the HTTP port specified as 4000 in the app configuration, but the container port isn’t getting exposed to the outside world.
How do I make sure public traffic can hit the 4000 port being exposed by the container?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hey!
To expose a Docker port to the public in DigitalOcean’s App Platform and ensure that public traffic can hit port 4000 exposed by your container, follow these steps:
1.First, ensure that your Dockerfile correctly exposes port 4000. You should have a line in your Dockerfile like this:
This tells Docker that the application running inside the container is listening on port 4000.
In your DigitalOcean App Platform app configuration, you need to specify that you want to route external HTTP traffic to your container’s port 4000. If you’re using the App Platform UI, you can specify this in the service configuration.
4000
.The App Platform sets the
PORT
environment variable inside your container to the port that your app should listen on (in this case, 4000). Ensure your application is configured to listen on the port specified by thePORT
environment variable.For example, in a Node.js application, you might have:
This setup ensures your app listens on the port defined by the
PORT
environment variable, which the App Platform sets to 4000.After updating your app’s configuration, redeploy your app. The DigitalOcean App Platform should now route traffic from the public internet to port 4000 on your container.
Once the deployment is complete, you should be able to access your application at the provided
.ondigitalocean.app
domain or any custom domain you have configured, without specifying the port number in the URL. Note that you will not have to add the port at the end of the hostname, the App Platform handles the routing to the correct container port based on your configuration.Hope that this helps!
Best,
Bobby