Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 435
Kay Avatar asked Jan 25 '19 15:01

Kay


People also ask

How do I stop docker from attaching?

Docker supports a keyboard combination to gracefully detach from a container. Press Ctrl-P, followed by Ctrl-Q, to detach from your connection. You'll be dropped back into your shell but the previously attached process will remain alive, keeping your container running.

What does docker compose up mean?

'docker-compose up' is a Docker command to start and run an entire app on a standalone host that contains multiple services, for example, Web, DB, etc. It can also create volumes and networks at the same time and attach to the containers that are defined in a file called 'docker-compose.


2 Answers

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.

like image 67
Ailson Forte Avatar answered Sep 23 '22 16:09

Ailson Forte


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
like image 20
dongi Avatar answered Sep 24 '22 16:09

dongi