Skip to content

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

@juanchax

Description

@juanchax
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions