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

Docker-Compose部署项目后www服务启动失败及浏览器访问问题

Troubleshooting Your Docker-Compose Deployment Issues

Let's break down your problems one by one—they’re likely connected, so fixing one might resolve the other:

1. WWW Service Failed to Start (Port Conflict Error)

That driver failed programming external connectivity error is almost always a port conflict: the port you’re trying to map from your container to the host is already being used by another process on your machine.

Here’s how to fix it:

  • First, check the ports section in your docker-compose.yml for the www service (e.g., if it’s 80:80, you’re trying to use host port 80).
  • Verify if that port is occupied:
    # For Linux/macOS
    sudo lsof -i :[YOUR_PORT]
    # For Windows
    netstat -ano | findstr :[YOUR_PORT]
    
  • If another process is using the port, either stop that process or change the host port in your docker-compose config (e.g., switch from 80:80 to 8080:80 so you access via localhost:8080).
  • Also, make sure old containers aren’t lingering—run docker-compose down -v to fully clean up previous containers and volumes before restarting.

2. Can’t Access the Project via Browser

This is probably tied to the first issue, but there’s a critical typo in your SQL script that might be breaking your app’s database connection too:

Looking at your script:

CREATE USER 'mgsv_user'@'localhost' IDENTIFIED BY 'mgsvpass';
GRANT SELECT, INSERT, CREATE, DROP ON mgsv.* TO 'mgsvuser'@'localhost';

You created a user named mgsv_user (with an underscore) but granted permissions to mgsvuser (no underscore)—that’s a mismatch! Plus, using localhost for the user’s host won’t work in Docker: your app runs in a separate container, so it won’t connect to the database via "localhost".

Fix your SQL script like this:

CREATE DATABASE mgsv;
-- Use '%' to allow connections from any container on the Docker network
CREATE USER 'mgsv_user'@'%' IDENTIFIED BY 'mgsvpass';
-- Match the username exactly to what you created
GRANT SELECT, INSERT, CREATE, DROP ON mgsv.* TO 'mgsv_user'@'%';
FLUSH PRIVILEGES; -- Ensure permissions take effect immediately

USE mgsv;
CREATE TABLE IF NOT EXISTS `userinfo` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `email` text NOT NULL,
  -- Add your remaining table fields here
  PRIMARY KEY (`id`)
);

Then, double-check your docker-compose.yml to ensure your app can reach the database correctly. Here’s a sample config snippet to reference:

services:
  db:
    image: mysql:5.7 # Or your preferred MySQL/MariaDB version
    environment:
      MYSQL_ROOT_PASSWORD: your_root_password_here
      MYSQL_DATABASE: mgsv
      MYSQL_USER: mgsv_user
      MYSQL_PASSWORD: mgsvpass
    volumes:
      - ./fixed-script.sql:/docker-entrypoint-initdb.d/init.sql # Mount your corrected script
    networks:
      - app-network

  www:
    build: . # Path to your app's Dockerfile
    ports:
      - "8080:80" # Adjusted port to avoid conflicts
    environment:
      DB_HOST: db # Use the database service name as the host (Docker DNS handles this)
      DB_USER: mgsv_user
      DB_PASSWORD: mgsvpass
      DB_NAME: mgsv
    depends_on:
      - db
    networks:
      - app-network

networks:
  app-network:
    driver: bridge

Final Steps to Redeploy

  1. Save your corrected SQL script
  2. Update your docker-compose.yml with the port and environment fixes
  3. Run docker-compose down -v to wipe old containers/volumes
  4. Run docker-compose up --build to rebuild and start everything
  5. Check the www service logs with docker-compose logs www to confirm no startup errors

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 11:09:15