Docker-compose hangs on Attaching to
Asked Answered
D

8

66

I have an issue when running docker-compose up. It hangs on attaching to and I cannot access my web app on localhost:4200.

docker-compose.yml:

version: '2' # specify docker-compose version

# Define the services/containers to be run
services:
  angular: # name of the first service
    build:
      context: . 
      dockerfile: ./.docker/scs.dockerfile  # specify the directory of the Dockerfile
    container_name: secure-cloud-storage-build-dev
    image: secure-cloud-storage
    ports:
      - "4200:4200" # specify port forwarding

dockerfile:

# Stage 0, based on Node.js, to build and compile Angular
FROM node:8.6 as node
WORKDIR /app
COPY package.json /app/
RUN npm install
COPY ./ /app/
ARG env=prod
RUN npm run build -- --prod --environment $env

# Stage 1, based on Nginx, to have only the compiled app, ready for production with Nginx
FROM nginx:1.13
COPY --from=node /app/dist/ /usr/share/nginx/html
COPY ./nginx-custom.conf /etc/nginx/conf.d/default.conf

nginx-custom.conf:

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

Here is verbose output:

docker-compose --verbose up output

Any clues what might be going wrong? I am quite fresh in Docker world, basically doing tutorials, so might be something obvious i missed. My localhost:4200 returns ERR_EMPTY_RESPONSE.

Davis answered 1/5, 2018 at 18:36 Comment(2)
create images first and then dcompoise it instead of using build .Constabulary
Your docker-compose.yaml specifies that your app in the container is running on port 4200, but your nginx-custom.conf listens on port 80. Those ports should match.Kemp
W
64

I know that I'm late to the party but this is to be expected. docker-compose up, just like docker run, requires a -d flag if you want to get your command line back.

Here is what the command would look like: docker-compose up -d

As far as why your app is returning an empty response I'm not sure.

Hope this helps others coming to this thread!

Wu answered 11/8, 2019 at 0:56 Comment(0)
P
8

In my case docker also hangs showing the "Attaching to ..." message, but the application works. So it seems to be a display issue that you can ignore.

You can run docker in detached mode docker-compose up -d angular to suppress this message. Till now I did not figure out how to run it in foreground mode without receiving the message.

Your configuration files in general look ok, but you have to configure the right ports i.e. nginx also needs to listen on port 4200.

Parmentier answered 27/7, 2018 at 9:25 Comment(0)
D
7

Docker-compose hangs on Attaching to

Seems silly but make sure the log is being written to stdout. I lost an hour to discover that the log was being written to a file.

If you are sure that logs should be printed, change the Ngnix configuration file to point the log to stdout. Read more on this thread.

The message Attaching to container seems a bit misleading to me. I thought Docker was in the process of attaching to the console but it was already attached. Everything else was working normally. The container was up.

My localhost:4200 returns ERR_EMPTY_RESPONSE

In your docker-compose.yml, map the port to where Ngnix is listening. Given the line listen 80;, in your case is 80:

ports:
  - "4200:80" # specify port forwarding
Dissemble answered 24/6, 2021 at 18:56 Comment(0)
S
5

If you end up here like I did where docker-compose didn't so much as hang but just exit: my problem was someone had added profiles to compose and I didn't catch that the bash script calling docker-compose didn't use the correct --profile argument.

If no profiles are matched, docker-compose will happily do nothing and simply say attaching to and then exit rather than something like "Hey, your profile argument matched nothing, did you do this on purpose?"

Seabrook answered 28/2, 2022 at 16:37 Comment(1)
It helped. So what I did was "docker-compose --profile=DEV up -d". See "profile:" section in your docker-compose.yml to figure out what to write instead of DEVAssurgent
S
1

Try to run this command in another terminal:

docker exec -it ${CONTAINERNAME} echo "Kick it" 

This for some reason helped with my hanging docker-compose attach to stuff. Seems like the STDOUT hangs for some reason and this kicks it further... Strangely it is only hanging when using docker-compose... Starting each service individually works as a charm...

Solly answered 10/9, 2020 at 4:54 Comment(1)
Didnt work for meLibbey
E
0

Make sure service names are unique

I was copy/pasting and ended up with two services with the same name

services: 
  node_server:
    ...

  node_server: # Duplicate service!
    ...

This can cause docker compose to hang on Attaching to

Edmundoedmunds answered 27/5, 2021 at 3:59 Comment(0)
D
0

If your code is working fine and you just see Attaching to [container name/id] then it is expected behaviour. After attaching it goes to print logs, but if there are no logs then it just waits in that running state, so if you are waiting for logs then there might be something wrong in your logger module check that to see your logs.

If you want up to exit use up -d.

Diarist answered 16/12, 2022 at 14:41 Comment(0)
O
0

I faced such problem when I mapped ports incorrectly.
I mapped:

  ports:
    - "11000:9000"

But app in container was launched at 8000 port. Respectively docker-compose tried to attach service on port which was not open.

Ottie answered 5/8, 2023 at 21:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.