Docker Install On Mac



If you're running macOS or Windows you have a few options for installing Docker. There's even a third way too, and we'll compare them here.

The fastest and easiest way to get started with Docker on Mac. Give feedback and get help. To get help from the community, review current user topics, join or start a discussion, log on to our Docker Desktop for Mac forum. To report bugs or problems, log on to Docker Desktop for Mac issues on GitHub, where you can review community reported issues, and file new ones. Download the (free) Docker Community Edition for Mac (unless you’ve already got it installed on your system). This will enable you to run SQL Server from within a Docker container. To download, visit the Docker CE for Mac download page and click Get Docker. The fastest and easiest way to get started with Docker on Mac. After furious account creating, downloading, installing and proxy-configuring the latest version of Docker was once again setup on my mac. Docker-compose up worked without any issues. I thing the problem was (or is) that my installment of Docker dated back to times when it was called Docker Toolbox (and did not include the docker-credential.

Quick Jump: OS and Hardware Requirements|Pros and Cons|Which One Should I Use?

If you’re on macOS or Windows you can install Docker with:

  1. Docker for Mac / Windows (now known as Docker Desktop)
  2. Docker Toolbox
  3. Running your own Virtual Machine and installing Docker yourself

All 3 of those options have their own pros and cons and in this article we’re going to cover them. If you’re looking for a high level overview of what Docker for Mac / Windows and Docker Toolbox is, then check out this article on getting to know Docker’s ecosystem.

OS and Hardware Requirements

It’s helpful to know what you can install before we compare everything, so let’s do that:

Docker for Mac (Docker Desktop)

Docker for Mac requires that you’re running Mojave 10.14+ or newer with an Intel CPU. M1 support is on its way.

You can run VirtualBox 6+ alongside Docker Desktop. This is pretty useful because you might have some legacy apps running in Vagrant / VirtualBox to deal with (I know I do!).

Docker Install On Mac

Docker for Windows (Docker Desktop)

As of May 27th 2020, Microsoft released Windows 10 build 2004 (Spring 2020) that allows you to run Docker Deskop on all editions of Windows 10, including Home thanks to WSL 2.

As of August 2020, Microsoft enabled WSL 2 support for Windows 10 builds 1903 + 1909.

For years prior to that you could only run it on Windows Pro, Enterprise or any edition that had Hyper-V available, but since August 2020 pretty much all supported versions of Windows 10 can use Docker Desktop.

You can also run VirtualBox 6+ alongside Docker Desktop too in case you have older projects using VirtualBox (perhaps with Vagrant too).

Docker Toolbox

Prior to mid-2020 this was still a reasonable way to run Docker on machines that couldn’t run Docker Desktop, but that’s no longer the case.

It’s now considered legacy and as of late 2020 it’s been officially deprecated.

Unless you’re using unsupported versions of Windows or have a really really ancient Mac you shouldn’t need to ever use this tool.

But if you’re in a pinch and you absolutely must use it, technically it’s still available at https://github.com/docker/toolbox/releases, but it’s no longer maintained by Docker.

Your own Virtual Machine

Docker will happily run inside of VirtualBox, VMWare Workstation or any other Type 1 / 2 Hypervisor that’s running a major distribution of Linux as a guest OS.

If for whatever reason you can’t use Docker Desktop then this solution would be better than using Docker Toolbox since you can install supported versions of Docker and you have full control over the environment.

Pros and Cons

Now for the good stuff!

Docker for Mac / Docker for Windows (Docker Desktop)

Pros
  • Offers the most “native” experience, you can easily use any terminal you you want since Docker is effectively running on localhost from macOS / Windows’ POV.

  • Docker is heavily developing and polishing this solution.

Cons
  • On certain macOS hardware combos the volume performance can be a little slow.

  • I can legit say there are not any “wow this sucks!” cons for Windows, it’s really solid.

Docker Toolbox

Pros
  • Offers an “out of the box” Docker experience if you have no other choice.
Cons
  • It’s deprecated by Docker and will receive no future maintenance.

  • You need to either use the Docker Quickstart Terminal, or configure your own terminal to connect to the Docker Daemon running a VM.

  • Not a native solution, so you’ll need to access your Docker Machine’s IP address if you’re developing web apps. Example: 192.168.99.100 instead of localhost.

  • Unless you jump through hoops, your code needs to live in your Windows user directory such as C:UsersNicksrcmyapp. Otherwise Docker won’t be able to find it.

  • Suffers from typical VirtualBox edge case bugs and mount performance issues.

Your own Virtual Machine

I’m not going to bother listing a pros and cons here because I wouldn’t recommend doing this UNLESS you’re stuck on Windows 7 / 8 or an older version of Windows 10 like 1809.

But more on that in a bit.

Which One Should I Use?

If you’re interested in Docker, you’re a smart person and you probably came to the conclusion that using Docker for Mac or Docker for Windows is a good idea as long as you can run it.

My recommendation would be to try Docker for Mac / Windows first, and test it against your actual use cases. The performance issues may or may not be a concern, especially since everyone’s needs and computer specs are different.

I’ve been using Docker Desktop on Windows for full time development since late 2018 and it’s been nothing short of fantastic. Currently I use it with WSL 2, but it was really good with WSL 1 along with Hyper-V too.

Stuck on an Old Version of Windows and Like Linux?

I want to mention a “roll your own VM” solution for Windows users because I feel like there’s an even better way to run Docker on Windows if you also like Linux and are stuck not being able to use modern versions of Windows 10.

It involves running VMWare Player in a special mode called “Unity mode”. This basically allows you to run Windows and Linux together seamlessly as 1 operating system.

There’s no dual booting and Linux applications (even graphical apps) run in their own floating windows. Then you can install Docker natively on Linux inside of the VM.

The performance is excellent and the entire set up is free too.

I used this set up for about 5 years until Docker Desktop was available. It gives you the best of both worlds. For example, I run high end audio / video apps on Windows while recording courses and screencasts that cover Linux content. It all works great (even for full time development).

You can watch a video guide and see screenshots on how to do that in this post on creating an awesome Linux development environment in Windows.

Are you using the Docker Toolbox, Docker for Mac / Windows or your own VM?

-->

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.

Docker Install On Mac Catalina

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.

  1. 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). 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 use sudo to run Docker, you can configure a docker group and add users to that group. For more information, see Post-installation steps for Linux.

  2. 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:

    ParameterDescription
    -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:1433Map 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 sql1Specify 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 sql1Used 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.
    -dRun the container in the background (daemon)
    mcr.microsoft.com/mssql/server:2017-latestThe SQL Server 2017 Linux container image.
  3. To view your Docker containers, use the docker ps command.

    You should see output similar to the following screenshot:

  4. 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.

  1. As a final step, change your SA password because the SA_PASSWORD is visible in ps -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.

  1. 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 use sudo to run Docker, you can configure a docker group and add users to that group. For more information, see Post-installation steps for Linux.

  2. 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:

    ParameterDescription
    -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:1433Map 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 sql1Specify 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 sql1Used 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-latestThe SQL Server 2019 Ubuntu Linux container image.
  3. To view your Docker containers, use the docker ps command.

    You should see output similar to the following screenshot:

  4. 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.

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.

  1. As a final step, change your SA password because the SA_PASSWORD is visible in ps -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.

  1. Choose a strong password to use for the SA user.

  2. 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.

  1. Use the docker exec -it command to start an interactive bash shell inside your running container. In the following example sql1 is name specified by the --name parameter when you created the container.

  2. 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.

  3. 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.

  1. From the sqlcmd command prompt, paste the following Transact-SQL command to create a test database:

  2. On the next line, write a query to return the name of all of the databases on your server:

  3. 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.

  1. From the sqlcmd command prompt, switch context to the new TestDB database:

  2. Create new table named Inventory:

  3. Insert data into the new table:

  4. Type GO to execute the previous commands:

Select data

Now, run a query to return data from the Inventory table.

  1. From the sqlcmd command prompt, enter a query that returns rows from the Inventory table where the quantity is greater than 152:

  2. Execute the command:

Exit the sqlcmd command prompt

  1. To end your sqlcmd session, type QUIT:

  2. 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.

  1. Find the IP address for the machine that hosts your container. On Linux, use ifconfig or ip addr. On Windows, use ipconfig.

  2. For this example, install the sqlcmd tool on your client machine. For more information, see Install sqlcmd on Windows or Install sqlcmd on Linux.

  3. 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.

  4. 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

Docker Install In Mac

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.