Docker get-started tutorial, port 3000 does not run the app

Viewed 1154

I am new to Docker and I am following their official tutorial - https://docs.docker.com/get-started/.

I am trying to start my container with this command - docker run -dp 3000:3000 getting-started.

However, when I am trying to open my browser to http://localhost:3000 I get enter image description here

I already did try to run it on different port - docker run -dp 3000:80 getting-started, however it redirects me to docker tutrial page and thats not what I want.

I have created a file app/Dockerfile with this content:

# syntax=docker/dockerfile:1
FROM node:12-alpine
RUN apk add --no-cache python3 g++ make
WORKDIR /app
COPY . .
RUN yarn install --production
CMD ["node", "src/index.js"]

I can't find the problem and I will be grateful for help.

2 Answers

Not sure if you ever solved this but I had a similar issue as I missed this all important line located in this section:

"If you haven't already done so, open a terminal and go to the app directory with the Dockerfile"

Your Dockerfile, as did mine in my http://localhost/tutorial/our-application/ does not have the

EXPOSE 3000

line at the end, whereas this line indeed appears in the Dockerfile in https://docs.docker.com/get-started/02_our_app/#build-the-apps-container-image (link provided in pbay's answer).

Without that line, the produced container does not expose port 3000, and docker start -dp 3000:(whatever) is bound to fail. [Edit: that's my understanding as a near-absolute beginner, but other people seem to have run that container successfully without that line. Go figure why/how. I'm ready to be enlightened.] In "Docker Desktop" on Windows, you can see in the dashboard that the container exits as soon as it starts.

I added that EXPOSE 3000 line, rebuild and rerun the using the same commands as first time:

docker build -t getting-started .
docker -dp 3000:3000 getting-started

and it now works fine.

(Rant: "If you've created Dockerfiles before, you might see a few flaws in the Dockerfile below" they say. Well this is not a minor flaw -- this is a beginner-discouraging trap. How come ?)

Related