79672122

Date: 2025-06-19 13:26:03
Score: 1
Natty:
Report link

Firstly, you should use the reference Connecting to SQL Server Database for creating SQL server user and password within docker container and apply security policies regarding password with the help of SQL Server Authentication - Modes and Setup.

Secondly, the challenge ” how can I move this password to an .env file or something similar where it is not stored as plain text?” faced by user in the given question can be solved using the reference: Login failed for user sa when i configure it through docker-compose · Issue #283 · microsoft/mssql-docker

Create a .env file: Store your sensitive data as key-value pairs in a .env file located in the same directory as your docker-compose.yml.

version: "3.8"
    services:
      my_service:
        image: my_image
        environment:
          - DB_USER=${DB_USER}
          - DB_PASSWORD=${DB_PASSWORD}
# In this example, DB_USER, and DB_PASSWORD are all values ​​read from environment variables.

# Strict mode variables
environment:
  API_KEY: ${API_KEY?err} # If not set, error "err" will be reported

Docker Compose will automatically load the .env file.

Docker Compose loads variables in the following order (later ones override earlier ones):

  1. .env File (autoload)

  2. Host environment variables

  3. --env-file Specified files

  4. environment Some directly defined values

Using Docker Secrets:

d.txt
    mypassword
version: "3.8"
    services:
      my_service:
        image: my_image
        environment:
           MYSQL_ROOT_PASSWORD_FILE: /run/secrets/mysql_root_password
        secrets:
          - mysql_root_password
    secrets:
      mysql_root_password:
        file: ./secrets/db_password.txt

For the full example of above codes follow this guide (PS: the guide page is in Chinese, try to translate it).

Reasons:
  • Blacklisted phrase (1): this guide
  • Blacklisted phrase (0.5): how can I
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (0.5):
Posted by: SoftSol