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

Docker运行正常但docker-compose启动MySQL容器失败求助

Fix for MySQL Docker-Compose Initialization Error

Ah, I spot the problem right away! Your docker-compose.yml has a small but critical syntax mistake in the environment section that's making MySQL think you didn't provide a root password.

The Issue

When using the array format (with - prefix) for environment variables in docker-compose, you need to use the KEY=VALUE syntax instead of a colon. Your line - MYSQL_ROOT_PASSWORD:12345678 uses a colon, which isn't recognized correctly in this context—Docker Compose isn't passing the password to the MySQL container properly, hence the "database is uninitialized and password option is not specified" error.

Correct Docker-Compose Config

You can fix this in two ways:

Option 1: Array Format with =

version: "3"
services:
  mysql:
    image: mysql:5.7.21
    environment:
      - MYSQL_ROOT_PASSWORD=12345678
    container_name: some-mysql

Option 2: Key-Value Format (No - prefix)

If you prefer the YAML key-value style, you can omit the hyphens and write it like this:

version: "3"
services:
  mysql:
    image: mysql:5.7.21
    environment:
      MYSQL_ROOT_PASSWORD: 12345678
    container_name: some-mysql

How to Apply the Fix

  1. Update your docker-compose.yml with either of the correct formats above.
  2. First, clean up any existing containers from your previous attempt (to avoid conflicts):
    docker-compose down
    
  3. Start the container again:
    docker-compose up -d
    

This should resolve the initialization error and get your MySQL container running just like it did with the docker run command.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 10:31:31