The recent effort to write case code WETEXT for the Apworks framework has been in free time every day. In the text publishing and processing microservices, I intend to use Microsoft's SQL Server for Linux to do the demo, so I joined the MS SQL Server service in my docker-compose. In fact, running SQL Server in Docker is very easy, so let's make an introduction today.
Start the Microsoft SQL Server 2017 container
Here is my docker-compose.yml file for infrastructure services in my current Wetext case (this file will change in the future, see GitHub for the latest version):
Version: "3" Services: MongoDB: image:mongo volumes: -${mongodb_database_volume} Container_ Name:mongodb Ports: -"27017:27017" Rabbit: image:rabbitmq:3-management ports: -" 5672:5672 " -" 4369:4369 " -" 5671:5671 " -" 25672:25672 " -" 15672:15672 " container_name: RABBITMQ hostname:my-rabbitmq volumes: -${rabbitmq_data_volume} Postgres: Image: Postgres Ports: -"5432:5432" container_name:postgres volumes: -${postgresql_data_ VOLUME} MSSQL: image:microsoft/mssql-server-linux:2017-latest ports: -"1433:1433" Container_name:mssql Environment: -accept_eula=y -[email protected]
This docker-compose file contains definitions of four services, and today we are only focusing on the last one, namely MSSQL. can see:
- The Docker image for Microsoft SQL Server is named: Microsoft/mssql-server-linux,tag to 2017-latest
- SQL Server listens on port 1433 in the container, which is the standard SQL Server port
- Starting the SQL Server container requires two environment variables: accept_eula=y, which indicates acceptance of the end User License Agreement, and[email protected], which indicates the password for the SA user is set. This user password to comply with strong password specification (number, letter, case, at least 8 characters), and then when the client connection, you need to use this password to log on to the server
Of course, instead of using docker-compose, you can use Docker run directly, and the method is similar, such as using the following statement:
sudo docker run-e ' accept_eula=y '-e ' [email protected] '- p 1433:1433--name MSSQL- D Microsoft/mssql-server-lin Ux:2017-latest
You can also start the SQL Server container. When running SQL Server in Docker, you need to be aware of:
- Host machine memory needs to be at least about 3.5GB
- The SQL Server in Docker is the developer version (Developer Edition), with the same functionality as the Enterprise Edition, but only for development or test environments and not for production environments
Connecting to SQL Server 2017
Official documentation describes using the Docker EXEC command to perform a sqlcmd command for connection and database use in a SQL Server 2017 container that is already running. Of course, you can also use graphical clients, such as SQL Server Management Studio or Visual Studio's Server Explorer, to connect to SQL Server running in Docker 2017, as is the method for connecting to the normal version of SQL Server. For example, the following is the effect of connecting Microsoft SQL Server on Linux for Docker in Visual Studio's Server Explorer:
Reference documents
- Run the SQL Server container image with Docker
- Docker Repository:microsoft/mssql-server-linux
Use Docker to run Microsoft SQL Server 2017