简体   繁体   English

docker-compose 对于 mssql 不使用 .env 文件?

[英]docker-compose for mssql not using .env file?

I have a.env file named .mssql filled with the basic MSSQL options:我有一个名为.mssql的 .env 文件,其中包含基本的 MSSQL 选项:

ACCEPT_EULA=Y
MSSQL_SA_PASSWORD=12Password34

My docker-compose.yml looks like this:我的docker-compose.yml看起来像这样:

version: '3'
services:
  db:
    image: "mcr.microsoft.com/mssql/server:2017-latest"
    volumes:
      - ./db-data:/var/opt/mssql
      - ./sql_scripts:/sql_scripts
    env_file:
      - .envs/.local/.mssql
    healthcheck:
      test: [ "CMD", "/opt/mssql-tools/bin/sqlcmd", "-S", "localhost", "-U", "sa", "-P", "$SA_PASSWORD", "-Q", "SELECT 1" ]
      interval: 30s
      timeout: 30s
      retries: 3
    # This command runs the sqlservr process and then runs the sql scripts in the sql_scripts folder - it uses init_done.flag to determine if it has already run
    command: /bin/bash -c '/opt/mssql/bin/sqlservr; if [ ! -f /sql_scripts/init_done.flag ]; then apt-get update && apt-get install -y mssql-tools unixodbc-dev; /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P $SA_PASSWORD -i /sql_scripts/db_setup.sql; /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P $SA_PASSWORD -i /sql_scripts/second_db_setup.sql; /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P $SA_PASSWORD -i /sql_scripts/third_db_setup.sql; touch /sql_scripts/init_done.flag; fi; tail -f /dev/null'
    ports:
      - 1433:1433
volumes:
  db-data:

When I run the command docker-compose up -d --build当我运行命令docker-compose up -d --build

It gives me a warning in the terminal where I ran the docker-compose command: WARN[0000] The "SA_PASSWORD" variable is not set. Defaulting to a blank string.它在我运行docker-compose命令的终端中发出警告: WARN[0000] The "SA_PASSWORD" variable is not set. Defaulting to a blank string. WARN[0000] The "SA_PASSWORD" variable is not set. Defaulting to a blank string.

Then when the container boots I see it begin the process without issue.然后,当容器启动时,我看到它毫无问题地开始了这个过程。 Then I see the following in the container logs:然后我在容器日志中看到以下内容:

Logon       Error: 18456, Severity: 14, State: 8.
Logon       Login failed for user 'sa'. Reason: Password did not match that for the login provided.

You set MSSQL_SA_PASSWORD in your env file.您在 env 文件中设置 MSSQL_SA_PASSWORD。 But as far as I see, in your Dockerfile you try to log in with $SA_PASSWORD.但据我所知,在您的 Dockerfile 中,您尝试使用 $SA_PASSWORD 登录。

So, either you change MSSQL_SA_PASSWORD to SA_PASSWORD in your env file or you change the Dockerfile (in the "test" and "command" section) from $SA_PASSWORD to $MSSQL_SA_PASSWORD.因此,要么在环境文件中将 MSSQL_SA_PASSWORD 更改为 SA_PASSWORD,要么将 Dockerfile(在“测试”和“命令”部分)从 $SA_PASSWORD 更改为 $MSSQL_SA_PASSWORD。 The second option could be preferred, since the image might additionally require MSSQL_SA_PASSWORD to be correctly set internally.第二个选项可能是首选,因为图像可能还需要在内部正确设置 MSSQL_SA_PASSWORD。 I can't tell you about that specifically, since I don't know the MSSQL image enough.我不能具体告诉你,因为我不太了解 MSSQL 图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM