Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Learn Docker/Writing a Dockerfile/EXPOSE instruction - Missing data and mismatched port information #875

Open
juanchax opened this issue Nov 23, 2024 · 0 comments

Comments

@juanchax
Copy link

  • The first line of the EXPOSE instruction explanation is missing part of the information.
  • The line below EXPOSE 80/udp states that we want to match the port exposed in our container with the one we have in src/index.js, but on the js file is 3000 and on the Dockerfile example provided it's 8000. Shouldn't it be the same?

EXPOSE instruction

EXPOSE specifies which ports the **<missing data>** when running the container. Each port is separated by a space ( ). By default the container listens using TCP, but UDP can be used by adding /udp after the port.

For example:

EXPOSE 80/udp

In our case, we want the port exposed by our container to match the port our application is running on (remember: const port = process.env.PORT || 3000 in src/index.js), therefore, we are publishing the value of our PORT environment variable.

ARG PORT=8000
ENV PORT=$PORT
...
EXPOSE $PORT

EXPOSE does not actually publish the port. When running the container with docker run, the -p flag needs to be used to access the port from your host machine. More on this in the next section. Learn more about EXPOSE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant