skip to Main Content

I am following this tutorial: https://docs.docker.com/get-started/02_our_app/

When I updated my app.js file as mentioned in the tutorial (it’s just a label change) then rebuilt and ran my image, Docker successfully runs the app but when I access localhost:3000 it gives me an error. The app was working fine before but now even if I download a fresh copy of the sample project and load it and follow the instruction from the start, accessing localhost:3000 is not showing me the app.

The error I get is this:

This page isn’t working
localhost didn’t send any data.
ERR_EMPTY_RESPONSE

Any hints here on what went wrong? And how can I fix it?

Additional information:

I am using macOS with an m1 chip.

Here is my Docker file code:

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

here is the command I run to build and run my Docker:

docker build -t getting-started .

docker run -p 3000:3000 getting-started

This is the log of Docker App when I click on the running container:

/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration

/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/

/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh

10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf

10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf

/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh

/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh

/docker-entrypoint.sh: Configuration complete; ready for start up


2021/08/13 09:26:50 [notice] 1#1: using the "epoll" event method

2021/08/13 09:26:50 [notice] 1#1: nginx/1.21.1

2021/08/13 09:26:50 [notice] 1#1: built by gcc 10.3.1 20210424 (Alpine 10.3.1_git20210424)

2021/08/13 09:26:50 [notice] 1#1: OS: Linux 5.10.25-linuxkit

2021/08/13 09:26:50 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576

2021/08/13 09:26:50 [notice] 1#1: start worker processes

2021/08/13 09:26:50 [notice] 1#1: start worker process 33

2021/08/13 09:26:50 [notice] 1#1: start worker process 34

2021/08/13 09:26:50 [notice] 1#1: start worker process 35

2021/08/13 09:26:50 [notice] 1#1: start worker process 36

Everything seems to be working except the localhost which was working fine until I modified the text and rebuilt the image and run it.

I have also placed the dockerfile in the correct location and have not modified any other file.

3

Answers


  1. You can check few things to get started again with :

    1. run command : docker ps -a
      This will give you all the containers running/stopped on the system. It will also list out ports being used , make sure only container uses the port you mapped while in running state or else it will give error.

    2. stop the containers by command : docker stop
      Container SHA value will be hex code diplayed in the first column when you run docker ps -a.

    3. Check the location of docker file as they have explicitly asked to put the file in app folder and also one more docker file is already present in getting started project folder so make sure you have not overwritten that file.

    I checked and performed the task it runs perfectly fine for me.

    Login or Signup to reply.
  2. I got the same issue, I fixed it by putting the dockerfile in the /app folder

    The github repo I cloned had it on the upper level and caused the issue.

    Login or Signup to reply.
  3. I had the same issue. You can check your docker app and see if you can click on the 3000:3000 Port if the container is running. For some reaseon I have to click that to see the page.

    If not you mightve opened up the wrong app folder in vs code. In my case I had opened vs code to the outer unzipped app folder that contained the other app folder. To fix it I opened the inner /app folder.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search