1

I created a docker-container based on nodejs. However, it seems to run fine, but both localhost:8080 and localhost:8443 and localhost can't connect. Also, the connection using curl produces the following message:

$ curl -vvv localhost:8080
*   Trying ::1:8080...
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
> GET / HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.67.0
> Accept: */*
> 
* Recv failure: Connection reset by peer
* Closing connection 0
curl: (56) Recv failure: Connection reset by peer
$ curl -vvv localhost:8443
*   Trying ::1:8443...
* TCP_NODELAY set
* Connected to localhost (::1) port 8443 (#0)
> GET / HTTP/1.1
> Host: localhost:8443
> User-Agent: curl/7.67.0
> Accept: */*
> 
* Recv failure: Connection reset by peer
* Closing connection 0
curl: (56) Recv failure: Connection reset by peer

This is docker-compose.yml

version: "2"
services:
  app:
    container_name: app_test
    restart: always
    build: .
    ports:
      - "8080:8080"
      - "8443:8443"

This is Dockerfile

FROM node:10.12.0

WORKDIR /usr/src/app

COPY package.json ./

RUN npm install

COPY . .

EXPOSE 80 # I try 3000, 8080 instead 80

CMD [ "node", "app.js" ]

And This is result of docker ps

docker ps
CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS              PORTS                                                    NAMES
735fba0a6ff5        IMAGE_NAME                  "node app.js"            46 seconds ago      Up 45 seconds       0.0.0.0:8080->8080/tcp, 80/tcp, 0.0.0.0:8443->8443/tcp   app_test

Neither curl nor browser runs. What should I do?

(I'm awkward because I'm not good at English. Please understand.)

3
  • 2
    You're node app is probably serving at port 3000? Commented Jan 2, 2020 at 14:07
  • @QuintenScheppermans This is ./bin/www If you look below it is connected to 3000. var port = normalizePort(process.env.PORT || '3000'); app.set('port', port); Commented Jan 2, 2020 at 14:10
  • Have you tried to add from your docker-compose file: ports: - "80:3000" Commented Jan 2, 2020 at 14:10

1 Answer 1

4
version: "2"
services:
  app:
    container_name: app_test
    restart: always
    build: .
    ports:
      - "8080:3000"
      - "8443:8443"

If you want access your app on localhost:8080, this should work. A node app serves on port 3000 as standard.

So basically:

{port host machine}:{port it actually runs on inside your container}

Sign up to request clarification or add additional context in comments.

5 Comments

I did try that. But result is same. Port part of the docker ps result 0.0.0.0:8443->8443/tcp, 0.0.0.0:8080->3000/tcp
What happens if you exec the command from within the container? "docker exec -it app_test bash" will open a shell, curl localhost:3000 there and tell me what happens.
Oh! restart docker and then process was successfully! Thank you.
@DOYEOPKIM , Please mark the answer as correct if it solved your problem.
This answer fixed my problem. It should be the correct answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.