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. Kitematicās one click install gets Docker running on your Mac and lets you control your app containers from a graphical user interface (GUI). Docker Hub Integration Easily search and pull your favorite images on Docker Hub from Kitematic GUI to create and run your app containers.
-->Run the following to get access to a Python prompt running in a Docker container: docker run -i -t python:3.6 This is equivalent to: docker run -it python:3.6 Running the Jupyter Notebook After running the previous command, you should have entered the Python prompt. @nabedge please use the š³ menu ļø `Diagnose and feedback' to upload a diagnostic log ball and add the output here. @LevonBecker, please do the same but create a fresh issue, although your symptoms seem similar the underlying cause could be different and it is far easier to de-dup issues than it is to split a single issue into two.
Applies to: SQL Server (all supported versions) - Linux
Note
The examples shown below use the docker.exe but most of these commands also work with Podman. It provides the CLI similar to Docker container Engine. You can read more about podman here.
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, 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 2017 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.
Tip
If 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
). Youtube desktop app for mac. 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.
Note
If you are using PowerShell Core, replace the double quotes with single quotes.
Note
The 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.
By 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. -h sql1 Used to explicitly set the container hostname, if you don't specify it, it defaults to the container ID which is a randomly generated system GUID. -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 as discussed above, 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.
- As a final step, change your SA password because the
SA_PASSWORD
is visible inps -eax
output and stored in the environment variable of the same name. See steps below.
Pull and run the 2019 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.
Note
If you are using PowerShell Core, replace the double quotes with single quotes.
Tip
This 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.
Note
The 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.
By 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. -h sql1 Used to explicitly set the container hostname, if you don't specify it, it defaults to the container ID which is a randomly generated system GUID. mcr.microsoft.com/mssql/server:2019-latest 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 Troubleshooting SQL Server Docker containers.
Run Docker Mac Install
The -h
(host name) parameter as discussed above, changes the internal name of the container to a custom value. 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.
- As a final step, change your SA password because the
SA_PASSWORD
is visible inps -eax
output and stored in the environment variable of the same name. See steps below.
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.
Tip
You 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 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. 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. You will also need to open the appropriate inbound port on your firewall to allow the connection.
Run Transact-SQL commands. When finished, type
QUIT
. Google duo for mac laptops.
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. Explore other scenarios, such as running multiple containers, data persistence, and troubleshooting.
Also, check out the mssql-docker GitHub repository for resources, feedback, and known issues.
Description
Run a command in a new container
Usage
Run Docker Mac Os
Options
Name, shorthand | Default | Description |
--add-host | Add a custom host-to-IP mapping (host:ip) | |
--attach , -a | Attach to STDIN, STDOUT or STDERR | |
--blkio-weight | Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0) | |
--blkio-weight-device | Block IO weight (relative device weight) | |
--cap-add | Add Linux capabilities | |
--cap-drop | Drop Linux capabilities | |
--cgroup-parent | Optional parent cgroup for the container | |
--cgroupns | API 1.41+ Cgroup namespace to use (host|private)'host': Run the container in the Docker host's cgroup namespace'private': Run the container in its own private cgroup namespace': Use the cgroup namespace as configured by the default-cgroupns-mode option on the daemon (default) | |
--cidfile | Write the container ID to the file | |
--cpu-count | CPU count (Windows only) | |
--cpu-percent | CPU percent (Windows only) | |
--cpu-period | Limit CPU CFS (Completely Fair Scheduler) period | |
--cpu-quota | Limit CPU CFS (Completely Fair Scheduler) quota | |
--cpu-rt-period | API 1.25+ Limit CPU real-time period in microseconds | |
--cpu-rt-runtime | API 1.25+ Limit CPU real-time runtime in microseconds | |
--cpu-shares , -c | CPU shares (relative weight) | |
--cpus | API 1.25+ Number of CPUs | |
--cpuset-cpus | CPUs in which to allow execution (0-3, 0,1) | |
--cpuset-mems | MEMs in which to allow execution (0-3, 0,1) | |
--detach , -d | Run container in background and print container ID | |
--detach-keys | Override the key sequence for detaching a container | |
--device | Add a host device to the container | |
--device-cgroup-rule | Add a rule to the cgroup allowed devices list | |
--device-read-bps | Limit read rate (bytes per second) from a device | |
--device-read-iops | Limit read rate (IO per second) from a device | |
--device-write-bps | Limit write rate (bytes per second) to a device | |
--device-write-iops | Limit write rate (IO per second) to a device | |
--disable-content-trust | true | Skip image verification |
--dns | Set custom DNS servers | |
--dns-opt | Set DNS options | |
--dns-option | Set DNS options | |
--dns-search | Set custom DNS search domains | |
--domainname | Container NIS domain name | |
--entrypoint | Overwrite the default ENTRYPOINT of the image | |
--env , -e | Set environment variables | |
--env-file | Read in a file of environment variables | |
--expose | Expose a port or a range of ports | |
--gpus | API 1.40+ GPU devices to add to the container ('all' to pass all GPUs) | |
--group-add | Add additional groups to join | |
--health-cmd | Command to run to check health | |
--health-interval | Time between running the check (ms|s|m|h) (default 0s) | |
--health-retries | Consecutive failures needed to report unhealthy | |
--health-start-period | API 1.29+ Start period for the container to initialize before starting health-retries countdown (ms|s|m|h) (default 0s) | |
--health-timeout | Maximum time to allow one check to run (ms|s|m|h) (default 0s) | |
--help | Print usage | |
--hostname , -h | Container host name | |
--init | API 1.25+ Run an init inside the container that forwards signals and reaps processes | |
--interactive , -i | Keep STDIN open even if not attached | |
--io-maxbandwidth | Maximum IO bandwidth limit for the system drive (Windows only) | |
--io-maxiops | Maximum IOps limit for the system drive (Windows only) | |
--ip | IPv4 address (e.g., 172.30.100.104) | |
--ip6 | IPv6 address (e.g., 2001:db8::33) | |
--ipc | IPC mode to use | |
--isolation | Container isolation technology | |
--kernel-memory | Kernel memory limit | |
--label , -l | Set meta data on a container | |
--label-file | Read in a line delimited file of labels | |
--link | Add link to another container | |
--link-local-ip | Container IPv4/IPv6 link-local addresses | |
--log-driver | Logging driver for the container | |
--log-opt | Log driver options | |
--mac-address | Container MAC address (e.g., 92:d0:c6:0a:29:33) | |
--memory , -m | Memory limit | |
--memory-reservation | Memory soft limit | |
--memory-swap | Swap limit equal to memory plus swap: '-1' to enable unlimited swap | |
--memory-swappiness | -1 | Tune container memory swappiness (0 to 100) |
--mount | Attach a filesystem mount to the container | |
--name | Assign a name to the container | |
--net | Connect a container to a network | |
--net-alias | Add network-scoped alias for the container | |
--network | Connect a container to a network | |
--network-alias | Add network-scoped alias for the container | |
--no-healthcheck | Disable any container-specified HEALTHCHECK | |
--oom-kill-disable | Disable OOM Killer | |
--oom-score-adj | Tune host's OOM preferences (-1000 to 1000) | |
--pid | PID namespace to use | |
--pids-limit | Tune container pids limit (set -1 for unlimited) | |
--platform | API 1.32+ Set platform if server is multi-platform capable | |
--privileged | Give extended privileges to this container | |
--publish , -p | Publish a container's port(s) to the host | |
--publish-all , -P | Publish all exposed ports to random ports | |
--pull | missing | Pull image before running ('always'|'missing'|'never') |
--read-only | Mount the container's root filesystem as read only | |
--restart | no | Restart policy to apply when a container exits |
--rm | Automatically remove the container when it exits | |
--runtime | Runtime to use for this container | |
--security-opt | Security Options | |
--shm-size | Size of /dev/shm | |
--sig-proxy | true | Proxy received signals to the process |
--stop-signal | SIGTERM | Signal to stop a container |
--stop-timeout | API 1.25+ Timeout (in seconds) to stop a container | |
--storage-opt | Storage driver options for the container | |
--sysctl | Sysctl options | |
--tmpfs | Mount a tmpfs directory | |
--tty , -t | Allocate a pseudo-TTY | |
--ulimit | Ulimit options | |
--user , -u | Username or UID (format: <name|uid>[:<group|gid>]) | |
--userns | User namespace to use | |
--uts | UTS namespace to use | |
--volume , -v | Bind mount a volume | |
--volume-driver | Optional volume driver for the container | |
--volumes-from | Mount volumes from the specified container(s) | |
--workdir , -w | Working directory inside the container |
Parent command
Command | Description |
---|---|
docker container | Manage containers |
Related commands
Run Docker Container On Remote Host
Command | Description |
docker container attach | Attach local standard input, output, and error streams to a running container |
docker container commit | Create a new image from a containerās changes |
docker container cp | Copy files/folders between a container and the local filesystem |
docker container create | Create a new container |
docker container diff | Inspect changes to files or directories on a containerās filesystem |
docker container exec | Run a command in a running container |
docker container export | Export a containerās filesystem as a tar archive |
docker container inspect | Display detailed information on one or more containers |
docker container kill | Kill one or more running containers |
docker container logs | Fetch the logs of a container |
docker container ls | List containers |
docker container pause | Pause all processes within one or more containers |
docker container port | List port mappings or a specific mapping for the container |
docker container prune | Remove all stopped containers |
docker container rename | Rename a container |
docker container restart | Restart one or more containers |
docker container rm | Remove one or more containers |
docker container run | Run a command in a new container |
docker container start | Start one or more stopped containers |
docker container stats | Display a live stream of container(s) resource usage statistics |
docker container stop | Stop one or more running containers |
docker container top | Display the running processes of a container |
docker container unpause | Unpause all processes within one or more containers |
docker container update | Update configuration of one or more containers |
docker container wait | Block until one or more containers stop, then print their exit codes |