As DBA, DevOps, and Data Engineer we should look for the most optimal way to maintain our environments however Docker Compose would be our best answer In a SQL Server Container world.
What is Docker Compose?
Docker Compose is a tool for defining and running multi-container Docker application and/or database services using a single YAML/YML file. With a single command, you create, start, and stop all the services from your configuration.
The features of Docker Compose that make it effective are:
- Multiple isolated environments on a single host
- Preserve volume data when containers are created
- Only recreate containers that have changed
- Variables and moving a composition between environments
Let’ us demo it. Copy below script, and save it as docker-compose.yml file.
version: '3.3' services: SQL-DB-Server: image: mcr.microsoft.com/mssql/server:2019-latest container_name: db-server-demo ports: - "1411:1433" - "5022:5022" environment: SA_PASSWORD: "Password0!" ACCEPT_EULA: "Y" MSSQL_AGENT_ENABLED: "true" MSSQL_MEMORY_LIMIT_MB: 4096 MSSQL_COLLATION: "Latin1_General_CI_AI" MSSQL_DATA_DIR: "/var/opt/mssql/data" MSSQL_LOG_DIR: "/var/opt/mssql/dblogs" MSSQL_BACKUP_DIR: "/var/opt/mssql/backups" MSSQL_DUMP_DIR: "/var/opt/mssql/sqldumps" volumes: - C:\mssql\data:/var/opt/mssql/data - C:\mssql\dblog:/var/opt/mssql/dblogs - C:\mssql\Backup:/var/opt/mssql/backups - C:\mssql\sqldumps:/var/opt/mssql/sqldumps - C:\mssql\logfile:/var/opt/mssql/log - C:\mssql\secrets:/var/opt/mssql/secrets
Please navigate under the directory where docker compose file is located then run docker-compose config script to validate docker-compose.yml file. If no error messages returned, then go ahead and execute below script to deploy SQL Server container using docker-compose.yml file.
docker-compose up -d
Docker Compose file is the recommended way for managing the whole life-cycle of your application or environments. Within a single file and command you are able to:
- Start, stop, and rebuild services
- View the status of running services
- Stream the log output of running services
- Run a one-off command on a service