-->![Macos Macos](/uploads/1/2/6/5/126533733/982890769.jpg)
Applies to:SQL Server (all supported versions) - Linux
Jul 30, 2017 Starting with SQL Server 2017, you can now install SQL Server directly on to a Linux machine. And because macOS is Unix based (and Linux is Unix based), you can run SQL Server for Linux on your Mac. The way to do this is to run SQL Server on Docker. So let’s go ahead and install Docker. Then we’ll download and install SQL Server. Jul 16, 2019 Prerequisites. To truly test this out on your own, there are some prerequisites you should be set up with. This is a big one: cross-platform SQL Server is only available for SQL Server 2017 and above, so make sure that version is compatible with whatever your building. The solution came with a realisation that sqlserver container runs inside docker-machine (with port forwarding between the two), but there is no forwarding from macOS host to docker-machine on tcp 1433 by default (to set up this forwarding, use the VBoxManage tweak for docker-machine, which was mentioned elsewhere). You are finally connected to SQL Server instance running on Mac Docker container and using SQL tool running natively on Mac OS too. You can now either create new db from script or restore it by first copying backup file into mapped Docker folder and then selecting the db backup file in Restore dialog of SQL Operations Studio. There are several MS SQL Server GUIs available for MacOS but I prefer to use VS Code since its my development tool of choice. To install the MS SQL extension on VS Code, click the extensions icon and type: mssql. From the search results, select SQL Server (mssql) and click Install. After the installation completes, select Reload to enable the.
Sep 26, 2019 When I wrote that, SQL Server 2017 was the latest version of SQL Server, and it had just been made available for Linux and Docker (which means that you can also install it on MacOS systems). In late 2018, Microsoft announced SQL Server 2019 Preview, and subsequently announced general release in late 2019.
In this quickstart, you use Docker to pull and run the SQL Server 2017 container image, mssql-server-linux. Then connect with sqlcmd to create your first database and run queries.
Tip
If you want to run SQL Server 2019 containers, see the SQL Server 2019 version of this article.
Note
Starting with SQL Server 2019 CU3, Ubuntu 18.04 is supported.
In this quickstart, you use Docker to pull and run the SQL Server 2019 container image, mssql-server. Then connect with sqlcmd to create your first database and run queries.
Tip
This quickstart creates SQL Server 2019 containers. If you prefer to create SQL Server 2017 containers, see the SQL Server 2017 version of this article.
This image consists of SQL Server running on Linux based on Ubuntu 18.04. It can be used with the Docker Engine 1.8+ on Linux or on Docker for Mac/Windows. This quickstart specifically focuses on using the SQL Server on linux image. The Windows image is not covered, but you can learn more about it on the mssql-server-windows-developer Docker Hub page.
Prerequisites
- Docker Engine 1.8+ on any supported Linux distribution or Docker for Mac/Windows. For more information, see Install Docker.
- Docker overlay2 storage driver. This is the default for most users. If you find that you are not using this storage provider and need to change, please see the instructions and warnings in the docker documentation for configuring overlay2.
- Minimum of 2 GB of disk space.
- Minimum of 2 GB of RAM.
- System requirements for SQL Server on Linux.
Pull and run the container image
Before starting the following steps, make sure that you have selected your preferred shell (bash, PowerShell, or cmd) at the top of this article.
- Pull the SQL Server 2017 Linux container image from Microsoft Container Registry.TipIf you want to run SQL Server 2019 containers, see the SQL Server 2019 version of this article.The previous command pulls the latest SQL Server 2017 container image. If you want to pull a specific image, you add a colon and the tag name (for example,
mcr.microsoft.com/mssql/server:2017-GA-ubuntu
). To see all available images, see the mssql-server Docker hub page.For the bash commands in this article,sudo
is used. On macOS,sudo
might not be required. On Linux, if you do not want to usesudo
to run Docker, you can configure a docker group and add users to that group. For more information, see Post-installation steps for Linux. - To run the container image with Docker, you can use the following command from a bash shell (Linux/macOS) or elevated PowerShell command prompt.NoteThe password should follow the SQL Server default password policy, otherwise the container can not setup SQL server and will stop working. By default, the password must be at least 8 characters long and contain characters from three of the following four sets: Uppercase letters, Lowercase letters, Base 10 digits, and Symbols. You can examine the error log by executing the docker logs command.NoteBy default, this creates a container with the Developer edition of SQL Server 2017. The process for running production editions in containers is slightly different. For more information, see Run production container images.The following table provides a description of the parameters in the previous
docker run
example:Parameter Description -e 'ACCEPT_EULA=Y' Set the ACCEPT_EULA variable to any value to confirm your acceptance of the End-User Licensing Agreement. Required setting for the SQL Server image. -e 'SA_PASSWORD=<YourStrong@Passw0rd>' Specify your own strong password that is at least 8 characters and meets the SQL Server password requirements. Required setting for the SQL Server image. -p 1433:1433 Map a TCP port on the host environment (first value) with a TCP port in the container (second value). In this example, SQL Server is listening on TCP 1433 in the container and this is exposed to the port, 1433, on the host. --name sql1 Specify a custom name for the container rather than a randomly generated one. If you run more than one container, you cannot reuse this same name. -d Run the container in the background (daemon) ** mcr.microsoft.com/mssql/server:2017-latest** The SQL Server 2017 Linux container image. - To view your Docker containers, use the
docker ps
command.You should see output similar to the following screenshot: - If the STATUS column shows a status of Up, then SQL Server is running in the container and listening on the port specified in the PORTS column. If the STATUS column for your SQL Server container shows Exited, see the Troubleshooting section of the configuration guide.
The
-h
(host name) parameter is also useful, but it is not used in this tutorial for simplicity. This changes the internal name of the container to a custom value. This is the name you'll see returned in the following Transact-SQL query:Setting
-h
and --name
to the same value is a good way to easily identify the target container.Pull and run the container image
Before starting the following steps, make sure that you have selected your preferred shell (bash, PowerShell, or cmd) at the top of this article.
- Pull the SQL Server 2019 Linux container image from Microsoft Container Registry.TipThis quickstart uses the SQL Server 2019 Docker image. If you want to run the SQL Server 2017 image, see the SQL Server 2017 version of this article.The previous command pulls the SQL Server 2019 container image based on Ubuntu. To instead use container images based on RedHat, see Run RHEL-based container images. To see all available images, see the mssql-server-linux Docker hub page.For the bash commands in this article,
sudo
is used. On macOS,sudo
might not be required. On Linux, if you do not want to usesudo
to run Docker, you can configure a docker group and add users to that group. For more information, see Post-installation steps for Linux. - To run the container image with Docker, you can use the following command from a bash shell (Linux/macOS) or elevated PowerShell command prompt.NoteThe password should follow the SQL Server default password policy, otherwise the container can not setup SQL server and will stop working. By default, the password must be at least 8 characters long and contain characters from three of the following four sets: Uppercase letters, Lowercase letters, Base 10 digits, and Symbols. You can examine the error log by executing the docker logs command.NoteBy default, this creates a container with the Developer edition of SQL Server 2019.The following table provides a description of the parameters in the previous
docker run
example:Parameter Description -e 'ACCEPT_EULA=Y' Set the ACCEPT_EULA variable to any value to confirm your acceptance of the End-User Licensing Agreement. Required setting for the SQL Server image. -e 'SA_PASSWORD=<YourStrong@Passw0rd>' Specify your own strong password that is at least 8 characters and meets the SQL Server password requirements. Required setting for the SQL Server image. -p 1433:1433 Map a TCP port on the host environment (first value) with a TCP port in the container (second value). In this example, SQL Server is listening on TCP 1433 in the container and this is exposed to the port, 1433, on the host. --name sql1 Specify a custom name for the container rather than a randomly generated one. If you run more than one container, you cannot reuse this same name. mcr.microsoft.com/mssql/server:2019-CU5-ubuntu-18.04 The SQL Server 2019 Ubuntu Linux container image. - To view your Docker containers, use the
docker ps
command.You should see output similar to the following screenshot: - If the STATUS column shows a status of Up, then SQL Server is running in the container and listening on the port specified in the PORTS column. If the STATUS column for your SQL Server container shows Exited, see the Troubleshooting section of the configuration guide.
The
-h
(host name) parameter is also useful, but it is not used in this tutorial for simplicity. This changes the internal name of the container to a custom value. This is the name you'll see returned in the following Transact-SQL query:Setting
-h
and --name
to the same value is a good way to easily identify the target container.Change the SA password
The SA account is a system administrator on the SQL Server instance that gets created during setup. After creating your SQL Server container, the
SA_PASSWORD
environment variable you specified is discoverable by running echo $SA_PASSWORD
in the container. For security purposes, change your SA password.- Choose a strong password to use for the SA user.
- Use
docker exec
to run sqlcmd to change the password using Transact-SQL. In the following example, replace the old password,<YourStrong!Passw0rd>
, and the new password,<YourNewStrong!Passw0rd>
, with your own password values.
Connect to SQL Server
The following steps use the SQL Server command-line tool, sqlcmd, inside the container to connect to SQL Server.
- Use the
docker exec -it
command to start an interactive bash shell inside your running container. In the following examplesql1
is name specified by the--name
parameter when you created the container. - Once inside the container, connect locally with sqlcmd. Sqlcmd is not in the path by default, so you have to specify the full path.TipYou can omit the password on the command-line to be prompted to enter it.
- If successful, you should get to a sqlcmd command prompt:
1>
.
Create and query data
The following sections walk you through using sqlcmd and Transact-SQL to create a new database, add data, and run a simple query.
Create a new database
The following steps create a new database named
TestDB
.- From the sqlcmd command prompt, paste the following Transact-SQL command to create a test database:
- On the next line, write a query to return the name of all of the databases on your server:
- The previous two commands were not executed immediately. You must type
GO
on a new line to execute the previous commands:
Insert data
Next create a new table,
Inventory
, and insert two new rows.- From the sqlcmd command prompt, switch context to the new
TestDB
database: - Create new table named
Inventory
: - Insert data into the new table:
- Type
GO
to execute the previous commands:
Select data
Now, run a query to return data from the
Inventory
table.- From the sqlcmd command prompt, enter a query that returns rows from the
Inventory
table where the quantity is greater than 152: - Execute the command:
Exit the sqlcmd command prompt
- To end your sqlcmd session, type
QUIT
: - To exit the interactive command-prompt in your container, type
exit
. Your container continues to run after you exit the interactive bash shell.
Connect from outside the container
You can also connect to the SQL Server instance on your Docker machine from any external Linux, Windows, or macOS tool that supports SQL connections.
The following steps use sqlcmd outside of your container to connect to SQL Server running in the container. These steps assume that you already have the SQL Server command-line tools installed outside of your container. The same principles apply when using other tools, but the process of connecting is unique to each tool.
- Find the IP address for the machine that hosts your container. On Linux, use ifconfig or ip addr. On Windows, use ipconfig.
- For this example, install the sqlcmd tool on your client machine. For more information, see Install sqlcmd on Windows or Install sqlcmd on Linux.
- Run sqlcmd specifying the IP address and the port mapped to port 1433 in your container. In this example, that is the same port, 1433, on the host machine. If you specified a different mapped port on the host machine, you would use it here.
- Run Transact-SQL commands. When finished, type
QUIT
.
Other common tools to connect to SQL Server include:
Remove your container
If you want to remove the SQL Server container used in this tutorial, run the following commands:
Warning
Stopping and removing a container permanently deletes any SQL Server data in the container. If you need to preserve your data, create and copy a backup file out of the container or use a container data persistence technique.
Docker demo
After you have tried using the SQL Server container image for Docker, you might want to know how Docker is used to improve development and testing. The following video shows how Docker can be used in a continuous integration and deployment scenario.
Next steps
For a tutorial on how to restore database backup files into a container, see Restore a SQL Server database in a Linux Docker container. To explore other scenarios, such as running multiple containers, data persistence, and troubleshooting, see Configure SQL Server container images on Docker.
Also, check out the mssql-docker GitHub repository for resources, feedback, and known issues.
-->Applies to:SQL Server (all supported versions) - Linux
This article explains how to configure and use the mssql-server-linux container image with Docker.
For other deployment scenarios, see:
This image consists of SQL Server running on Linux based on Ubuntu 16.04. It can be used with the Docker Engine 1.8+ on Linux or on Docker for Mac/Windows.
Note
This article specifically focuses on using the mssql-server-linux image. The Windows image is not covered, but you can learn more about it on the mssql-server-windows Docker Hub page.
Important
Before choosing to run a SQL Server container for production use cases, please review our support policy for SQL Server Containers to ensure that you are running on a supported configuration.
This 6-minute video provides an introduction into running SQL Server on containers:
Pull and run the container image
To pull and run the Docker container images for SQL Server 2017 and SQL Server 2019, follow the prerequisites and steps in the following quickstart:
This configuration article provides additional usage scenarios in the following sections.
Run RHEL-based container images
The documentation for SQL Server Linux container images points to Ubuntu-based containers. Beginning with SQL Server 2019, you can use containers based on Red Hat Enterprise Linux (RHEL). Change the container repository from mcr.microsoft.com/mssql/server:2019-GA-ubuntu-16.04 to mcr.microsoft.com/mssql/rhel/server:2019-CU1-rhel-8 in all of your docker commands.
For example, the following command pulls the Cumulative Update 1 for SQL Server 2019 container that uses RHEL 8:
Run production container images
The quickstart in the previous section runs the free Developer edition of SQL Server from Docker Hub. Most of the information still applies if you want to run production container images, such as Enterprise, Standard, or Web editions. However, there are a few differences that are outlined here.
- You can only use SQL Server in a production environment if you have a valid license. You can obtain a free SQL Server Express production license here. SQL Server Standard and Enterprise Edition licenses are available through Microsoft Volume Licensing.
- The Developer container image can be configured to run the production editions as well. Use the following steps to run production editions:
Review the requirements and run procedures in the quickstart. You must specify your production edition with the MSSQL_PID environment variable. The following example shows how to run the latest SQL Server 2017 container image for the Enterprise Edition:
Important
By passing the value Y to the environment variable ACCEPT_EULA and an edition value to MSSQL_PID, you are expressing that you have a valid and existing license for the edition and version of SQL Server that you intend to use. You also agree that your use of SQL Server software running in a Docker container image will be governed by the terms of your SQL Server license.
Note
For a full list of possible values for MSSQL_PID, see Configure SQL Server settings with environment variables on Linux.
Connect and query
You can connect and query SQL Server in a container from either outside the container or from within the container. The following sections explain both scenarios.
Tools outside the container
You can connect to the SQL Server instance on your Docker machine from any external Linux, Windows, or macOS tool that supports SQL connections. Some common tools include:
The following example uses sqlcmd to connect to SQL Server running in a Docker container. The IP address in the connection string is the IP address of the host machine that is running the container.
If you mapped a host port that was not the default 1433, add that port to the connection string. For example, if you specified
-p 1400:1433
in your docker run
command, then connect by explicitly specify port 1400.Tools inside the container
Starting with SQL Server 2017, the SQL Server command-line tools are included in the container image. If you attach to the image with an interactive command-prompt, you can run the tools locally.
- Use the
docker exec -it
command to start an interactive bash shell inside your running container. In the following examplee69e056c702d
is the container ID.TipYou don't always have to specify the entire container id. You only have to specify enough characters to uniquely identify it. So in this example, it might be enough to usee6
ore69
rather than the full id. - Once inside the container, connect locally with sqlcmd. Note that sqlcmd is not in the path by default, so you have to specify the full path.
- When finished with sqlcmd, type
exit
. - When finished with the interactive command-prompt, type
exit
. Your container continues to run after you exit the interactive bash shell.
Run multiple SQL Server containers
Docker provides a way to run multiple SQL Server containers on the same host machine. Use this approach for scenarios that require multiple instances of SQL Server on the same host. Each container must expose itself on a different port.
The following example creates two SQL Server 2017 containers and maps them to ports 1401 and 1402 on the host machine.
The following example creates two SQL Server 2019 containers and maps them to ports 1401 and 1402 on the host machine.
Now there are two instances of SQL Server running in separate containers. Clients can connect to each SQL Server instance by using the IP address of the Docker host and the port number for the container.
Create a customized container
It is possible to create your own Dockerfile to create a customized SQL Server container. For more information, see a demo that combines SQL Server and a Node application. If you do create your own Dockerfile, be aware of the foreground process, because this process controls the life of the container. If it exits, the container will shutdown. For example, if you want to run a script and start SQL Server, make sure that the SQL Server process is the right-most command. All other commands are run in the background. The following command illustrates this inside a Dockerfile:
If you reversed the commands in the previous example, the container would shutdown when the do-my-sql-commands.sh script completes.
Persist your data
Your SQL Server configuration changes and database files are persisted in the container even if you restart the container with
docker stop
and docker start
. However, if you remove the container with docker rm
, everything in the container is deleted, including SQL Server and your databases. The following section explains how to use data volumes to persist your database files even if the associated containers are deleted.Important
For SQL Server, it is critical that you understand data persistence in Docker. In addition to the discussion in this section, see Docker's documentation on how to manage data in Docker containers.
Mount a host directory as data volume
Dockerfile For Sql Server On Macos Windows 10
The first option is to mount a directory on your host as a data volume in your container. To do that, use the
docker run
command with the -v <host directory>:/var/opt/mssql
flag. This allows the data to be restored between container executions.This technique also enables you to share and view the files on the host outside of Docker.
Important
Host volume mapping for Docker on Windows does not currently support mapping the complete
/var/opt/mssql
directory. However, you can map a subdirectory, such as /var/opt/mssql/data
to your host machine.Important
Host volume mapping for Docker on Mac with the SQL Server on Linux image is not supported at this time. Use data volume containers instead. This restriction is specific to the
/var/opt/mssql
directory. Reading from a mounted directory works fine. For example, you can mount a host directory using -v on Mac and restore a backup from a .bak file that resides on the host.Use data volume containers
The second option is to use a data volume container. You can create a data volume container by specifying a volume name instead of a host directory with the
-v
parameter. The following example creates a shared data volume named sqlvolume.Note
This technique for implicitly creating a data volume in the run command does not work with older versions of Docker. In that case, use the explicit steps outlined in the Docker documentation, Creating and mounting a data volume container.
Even if you stop and remove this container, the data volume persists. You can view it with the
docker volume ls
command.If you then create another container with the same volume name, the new container uses the same SQL Server data contained in the volume.
To remove a data volume container, use the
docker volume rm
command.Warning
If you delete the data volume container, any SQL Server data in the container is permanently deleted.
Backup and restore
In addition to these container techniques, you can also use standard SQL Server backup and restore techniques. You can use backup files to protect your data or to move the data to another SQL Server instance. For more information, see Backup and restore SQL Server databases on Linux.
Warning
If you do create backups, make sure to create or copy the backup files outside of the container. Otherwise, if the container is removed, the backup files are also deleted.
Execute commands in a container
If you have a running container, you can execute commands within the container from a host terminal.
To get the container ID run:
To start a bash terminal in the container run:
Now you can run commands as though you are running them at the terminal inside the container. When finished, type
exit
. This exits in the interactive command session, but your container continues to run.Copy files from a container
To copy a file out of the container, use the following command:
Example:
Copy files into a container
To copy a file into the container, use the following command:
Example:
Configure the timezone
To run SQL Server in a Linux container with a specific timezone, configure the
TZ
environment variable. To find the right timezone value, run the tzselect
command from a Linux bash prompt:After selecting the timezone,
tzselect
displays output similar to the following:You can use this information to set the same environment variable in your Linux container. The following example shows how to run SQL Server in a container in the
Americas/Los_Angeles
timezone:Run a specific SQL Server container image
There are scenarios where you might not want to use the latest SQL Server container image. To run a specific SQL Server container image, use the following steps:
- Identify the Docker tag for the release you want to use. To view the available tags, see the mssql-server-linux Docker hub page.
- Pull the SQL Server container image with the tag. For example, to pull the RC1 image, replace
<image_tag>
in the following command withrc1
. - To run a new container with that image, specify the tag name in the
docker run
command. In the following command, replace<image_tag>
with the version you want to run.
These steps can also be used to downgrade an existing container. For example, you might want to rollback or downgrade a running container for troubleshooting or testing. To downgrade a running container, you must be using a persistence technique for the data folder. Follow the same steps outlined in the upgrade section, but specify the tag name of the older version when you run the new container.
Check the container version
If you want to know the version of SQL Server in a running docker container, run the following command to display it. Replace
<Container ID or name>
with the target container ID or name. Replace <YourStrong!Passw0rd>
with the SQL Server password for the SA login.You can also identify the SQL Server version and build number for a target docker container image. The following command displays the SQL Server version and build information for the mcr.microsoft.com/mssql/server:2017-latest image. It does this by running a new container with an environment variable PAL_PROGRAM_INFO=1. The resulting container instantly exits, and the
docker rm
command removes it.The previous commands display version information similar to the following output:
Upgrade SQL Server in containers
To upgrade the container image with Docker, first identify the tag for the release for your upgrade. Pull this version from the registry with the
docker pull
command:This updates the SQL Server image for any new containers you create, but it does not update SQL Server in any running containers. To do this, you must create a new container with the latest SQL Server container image and migrate your data to that new container.
- Make sure you are using one of the data persistence techniques for your existing SQL Server container. This enables you to start a new container with the same data.
- Stop the SQL Server container with the
docker stop
command. - Create a new SQL Server container with
docker run
and specify either a mapped host directory or a data volume container. Make sure to use the specific tag for your SQL Server upgrade. The new container now uses a new version of SQL Server with your existing SQL Server data.ImportantUpgrade is only supported between RC1, RC2, and GA at this time. - Verify your databases and data in the new container.
- Optionally, remove the old container with
docker rm
.
Build and run non-root SQL Server 2017 containers
Follow the steps below to build a SQL Server 2017 container that starts up as the
mssql
(non-root) user.Note
SQL Server 2019 containers automatically start up as non-root, so the following steps only apply to SQL Server 2017 containers, which start as root by default.
- Download the sample dockerfile for non-root SQL Server Container and save it as
dockerfile
. - Run the following command in the context of the dockerfile directory to build the non-root SQL Server container:
- Start the container.
Note
The
--cap-add SYS_PTRACE
flag is required for non-root SQL Server containers to generate dumps for troubleshooting purposes.- Check that the container is running as non-root user:
docker exec into the container.
Run
whoami
which will return the user running within the container.Run container as a different non-root user on the host
![Macos Macos](/uploads/1/2/6/5/126533733/982890769.jpg)
To run the SQL Server container as a different non-root user, add the -u flag to the docker run command. The non-root container has the restriction that it must run as part of the root group unless a volume is mounted to '/var/opt/mssql' that the non-root user can access. The root group doesn’t grant any extra root permissions to the non-root user.
Run as a user with a UID 4000
You can start SQL Server with a custom UID. For example, the command below starts SQL Server with UID 4000:
Warning
Ensure that the SQL Server container has a named user such as 'mssql' or 'root' or SQLCMD will not be able to run within the container. You can check if the SQL Server container is running as a named user by running
whoami
within the container.Run the non-root container as the root user
You can run the non-root container as the root user if required. This would also grant all file permissions automatically to the container because it is higher privilege.
Run as a user on your host machine
You can start SQL Server with an existing user on the host machine with the following command:
Run as a different user and group
You can start SQL Server with a custom user and group. In this example, the mounted volume has permissions configured for the user or group on the host machine.
Configure persistent storage permissions for non-root containers
To allow the non-root user to access DB files that are on mounted volumes, ensure that the user/group you run the container under can touch the persistent file storage.
You can get the current ownership of the database files with this command.
Run one of the following commands if SQL Server does not have access to persisted database files.
Grant the root group r/w access to the DB files
Grant the root group permissions to the following directories so that the non-root SQL Server container has access to database files.
Set the non-root user as the owner of the files.
This can be the default non-root user, or any other non-root user you’d like to specify. In this example, we set UID 10001 as the non-root user.
Change the default file location
Add the
MSSQL_DATA_DIR
variable to change your data directory in your docker run
command, then mount a volume to that location that your container’s user has access to.Troubleshooting
The following sections provide troubleshooting suggestions for running SQL Server in containers.
Docker command errors
If you get errors for any
docker
commands, make sure that the docker service is running, and try to run with elevated permissions.For example, on Linux, you might get the following error when running
docker
commands:If you get this error on Linux, try running the same commands prefaced with
sudo
. If that fails, verify the docker service is running, and start it if necessary.On Windows, verify that you are launching PowerShell or your command-prompt as an Administrator.
SQL Server container startup errors
If the SQL Server container fails to run, try the following tests:
- If you get an error such as 'failed to create endpoint CONTAINER_NAME on network bridge. Error starting proxy: listen tcp 0.0.0.0:1433 bind: address already in use.', then you are attempting to map the container port 1433 to a port that is already in use. This can happen if you're running SQL Server locally on the host machine. It can also happen if you start two SQL Server containers and try to map them both to the same host port. If this happens, use the
-p
parameter to map the container port 1433 to a different host port. For example:
- If you get an error such as 'Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.30tdout=1&tail=all: dial unix /var/run/docker.sock: connect: permission denied' when trying to start a container, then add your user to the docker group in Ubuntu. Then logout and login again as this change will affect new sessions.
- Check to see if there are any error messages from container.
- Make sure that you meet the minimum memory and disk requirements specified in the prerequisites section of the quickstart article.
- If you are using any container management software, make sure it supports container processes running as root. The sqlservr process in the container runs as root.
- Review the SQL Server setup and error logs.
Enable dump captures
If the SQL Server process is failing inside the container, you should create a new container with SYS_PTRACE enabled. This adds the Linux capability to trace a process, which is necessary for creating a dump file on an exception. The dump file can be used by support to help troubleshoot the problem. The following docker run command enables this capability.
SQL Server connection failures
If you can't connect to the SQL Server instance running in your container, try the following tests:
- Make sure that your SQL Server container is running by looking at the STATUS column of the
docker ps -a
output. If not, usedocker start <Container ID>
to start it. - If you mapped to a non-default host port (not 1433), make sure you are specifying the port in your connection string. You can see your port mapping in the PORTS column of the
docker ps -a
output. For example, the following command connects sqlcmd to a container listening on port 1401: - If you used
docker run
with an existing mapped data volume or data volume container, SQL Server ignores the value ofMSSQL_SA_PASSWORD
. Instead, the pre-configured SA user password is used from the SQL Server data in the data volume or data volume container. Verify that you are using the SA password associated with the data you're attaching to. - Review the SQL Server setup and error logs.
SQL Server Availability Groups
If you are using Docker with SQL Server Availability Groups, there are two additional requirements.
- Map the port that is used for replica communication (default 5022). For example, specify
-p 5022:5022
as part of yourdocker run
command. - Explicitly set the container host name with the
-h YOURHOSTNAME
parameter of thedocker run
command. This host name is used when you configure your Availability Group. If you don't specify it with-h
, it defaults to the container ID.
SQL Server setup and error logs
You can look at the SQL Server setup and error logs in /var/opt/mssql/log. If the container is not running, first start the container. Then use an interactive command-prompt to inspect the logs.
From the bash session inside your container, run the following commands:
Tip
If you mounted a host directory to /var/opt/mssql when you created your container, you can instead look in the log subdirectory on the mapped path on the host.
Next steps
Get started with SQL Server 2017 container images on Docker by going through the quickstart.
Also, see the mssql-docker GitHub repository for resources, feedback, and known issues.