You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker-compose up卡在Attaching to,无法访问localhost:4200应用

Hey there, let's tackle this issue step by step! When docker-compose up gets stuck at the Attaching to stage and your Angular app isn't reachable on localhost:4200, there are several common fixes and checks we can run through:

1. First, confirm if your container is actually running

  • Run docker-compose ps or docker ps to check the status of your secure-cloud-storage-build-dev container. If it shows as Exited, you need to dig into the logs to find why it failed to start:
    docker-compose logs angular
    # Or directly check the container logs
    docker logs secure-cloud-storage-build-dev
    
    Look for errors like missing dependencies, failed npm installs, or invalid startup commands in the output.

2. Verify port mapping and internal service listening

  • Check if port 4200 is occupied on your host machine:
    • On Linux/macOS: lsof -i :4200
    • On Windows: netstat -ano | findstr :4200
      If another process is using the port, either change the host port in your docker-compose.yml (e.g., "4201:4200") or shut down the conflicting process.
  • Check if the Angular service is listening inside the container:
    Enter the container with:
    docker exec -it secure-cloud-storage-build-dev bash
    
    Then run:
    netstat -tulpn | grep 4200
    # Or use ss if netstat isn't installed
    ss -tulpn | grep 4200
    
    If you don't see any output here, the Angular dev server isn't binding to the right interface. By default, ng serve only listens on localhost inside the container—you need to make it listen on all interfaces with --host 0.0.0.0.

3. Fix your Dockerfile's startup command

  • Open your .docker/scs.dockerfile and check the final CMD or ENTRYPOINT line. If it looks like this:
    CMD ["ng", "serve"]
    
    Update it to:
    CMD ["ng", "serve", "--host", "0.0.0.0"]
    
    This ensures the Angular server accepts connections from outside the container (via your port mapping). Also, double-check that your Dockerfile runs npm install or yarn install correctly to pull all required dependencies before starting the server.

4. Tweak docker-compose.yml for interactive terminal support

  • Angular's dev server sometimes requires an interactive terminal to run properly. Add these two lines to your angular service configuration:
    services:
      angular:
        # ... existing config
        stdin_open: true
        tty: true
    
    This can prevent the process from hanging at the Attaching to stage.

5. Clean up old builds and restart fresh

  • Cached images or containers can cause unexpected issues. Run these commands to start from scratch:
    # Stop and remove existing containers
    docker-compose down
    # Delete the old built image
    docker rmi secure-cloud-storage
    # Rebuild and restart
    docker-compose up --build
    

内容的提问来源于stack exchange,提问作者PerlMonk92

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 10:06:50