'docker-compose up stuck on attaching to

Im trying to dockerize my react app.

Whenever i run docker-compose up it gets stuck on "Attaching to"

Dockerfile

# Stage 0 - Pre-requisite: Based On Node.js to BUILD and compile App.

FROM node:10.15.0-alpine as node

WORKDIR /app

COPY package.json /app/

RUN npm install 

COPY ./ /app/

RUN npm run build

# Stage 1 - Based On Nginx to have ONLY a compiled and PRODUCTION ready build.

FROM nginx:1.15.8-alpine

COPY --from=node /app/build/ /usr/share/nginx/html

COPY ./nginx-custom.conf /etc/nginx/conf.d/default.conf

docker-compose.yml

version: '3'

services:
  idcheck-demo:
    image: idcheck-demo
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - 8080:8080

nginx-custom.conf

server {
    listen 8080;
    location / {
        root /usr/share/nginx/html;
        index index.html index.htm;
        try_files $uri $uri/ /index.html =404;
    }
}

Ive tried attempting to access it by going to 0.0.0.0:8080 but it just returns me with the following error in the browser

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



Solution 1:[1]

In my case was a port forwarding at the docker-compose.yml. I was doing the forward to 8080 when the exposed port was the 80 so when I've changed the port forwarding to 80 at the docker-compose.yml the service have done as should be.

Solution 2:[2]

First check if the container is up. You can do this by running:

docker-compose ps

In case of your configuration I got:

         Name                   Command          State               Ports             
---------------------------------------------------------------------------------------
54368216_idcheck-demo_1   nginx -g daemon off;   Up      80/tcp, 0.0.0.0:8080->8080/tcp

as you can see container is running with nginx not being daemonized which explains why the console is hanging after you run docker-compose up.

You can also run a quick telnet to see if the HTTP service is responding correctly:

telnet localhost 8080
Trying ::1...
Connected to localhost.
Escape character is '^]'.

Bottom line is that console stuck on "Attaching to..." is caused by the nginx process not running as a daemon.

You can put the container into background running:

docker-compose up -d

Solution 3:[3]

I got this problem when I start nginx using "docker-compose up". And the reason is Port Conflict, so I fix it by changing Ports Configuration.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 chevybow
Solution 2
Solution 3 yunfang