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

Docker Compose报错:services.sqlserver.build含不支持的'environment'选项

Fixing "Docker Compose contains unsupported option: 'environment'" Error

Let's jump straight to the issue here. The error you're seeing happens because you've placed the environment configuration inside the build block of your sqlserver service—but environment is a top-level setting for the service itself, not part of the build context setup.

What's Wrong With Your Current Config

Your docker-compose.yml has the environment keys nested under services.sqlserver.build, which isn't a valid location for runtime environment variables in Docker Compose v3:

version: "3"
services:
  coreapi:
    build:
      context: ./theapi
      dockerfile: Dockerfile
    ports:
      - "5000:5000"
  sqlserver:
    build:
      context: ./sqlserver
      environment:  # ❌ This is the incorrect placement
        ACCEPT_EULA="Y"
        SA_PASSWORD="Pwd12345!"
    ports:
      - "11433:1433"

Corrected docker-compose.yml

Move the environment block out of build and make it a direct child of the sqlserver service. Also, Docker Compose environment variables don't require quotes (though they might work in some cases, omitting them follows the standard YAML syntax):

version: "3"
services:
  coreapi:
    build:
      context: ./theapi
      dockerfile: Dockerfile
    ports:
      - "5000:5000"
  sqlserver:
    build:
      context: ./sqlserver
    environment:  # ✅ Correct service-level placement
      ACCEPT_EULA: Y
      SA_PASSWORD: Pwd12345!
    ports:
      - "11433:1433"

Why This Works

  • The build block is only for configuring how your Docker image gets built (like context path, Dockerfile location, or build-time arguments).
  • The environment block at the service level sets variables that will be available inside the running container—exactly what you need for SQL Server's setup requirements (ACCEPT_EULA and SA_PASSWORD).

Quick Additional Tips

  • If you ever need to pass build-time only variables (used during image creation but not in the running container), use args inside the build block instead of environment. For example:
    build:
      context: ./sqlserver
      args:
        BUILD_VERSION: 1.0.0
    
  • Double-check YAML indentation—it's strict! Make sure all service-level keys (build, environment, ports) are aligned at the same indentation level.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.07 08:12:52