Question

How to expose Docker port to public in App Platform?

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?


Submit an answer


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!

Sign In or Sign Up to Answer

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.

Bobby Iliev
Site Moderator
Site Moderator badge
March 21, 2024

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:

EXPOSE 4000

This tells Docker that the application running inside the container is listening on port 4000.

  1. 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.

    • Go to the “Settings” tab of your app in the DigitalOcean control panel.
    • In the “HTTP Port” field, make sure you enter 4000.
  2. 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 the PORT environment variable.

    For example, in a Node.js application, you might have:

    const port = process.env.PORT || 3000;
    app.listen(port, () => {
      console.log(`Server running on port ${port}`);
    });
    

    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

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel