Skip to content

Instantly share code, notes, and snippets.

@ngnam
Last active July 20, 2023 07:46
Show Gist options
  • Save ngnam/50ab700ba3e5fc681dd818009a7850a4 to your computer and use it in GitHub Desktop.
Save ngnam/50ab700ba3e5fc681dd818009a7850a4 to your computer and use it in GitHub Desktop.

Pull and run the SQL Server Linux container image

Choose your command shell PowerShell or Cmd

  1. Pull the SQL Server 2022 (16.x) Linux container image from the Microsoft Container Registry.

docker pull mcr.microsoft.com/mssql/server:2022-latest

  1. run linux container image
docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=<YourStrong@Passw0rd>" `
   -p 1433:1433 --name sql1 --hostname sql1 `
   -d `
   mcr.microsoft.com/mssql/server:2022-latest

doc here https://learn.microsoft.com/en-us/sql/linux/quickstart-install-connect-docker?view=sql-server-ver16&pivots=cs1-cmd

  1. Change the system administrator password
docker exec -it sql1 /opt/mssql-tools/bin/sqlcmd `
   -S localhost -U SA -P "<YourStrong@Passw0rd>" `
   -Q "ALTER LOGIN SA WITH PASSWORD='<YourNewStrong@Passw0rd>'"

How to install docker-desktop-on-a-different-drive-on-windows-10/11

To install docker on, say, E:\Docker\Docker drive I did the following:

Don't install using double click on "Docker Desktop Installer.exe". Open windows terminal as Administrator.(Right click on the Terminal icon and click on Run as administrator). Goto the folder where "Docker Desktop Installer.exe" downloaded. And run start /w "" "Docker Desktop Installer.exe" install -accept-license --installation-dir=E:\Docker\Docker One thing it will install docker to separate drive. But the WSL, image etc still will be in %HOME%\AppData\Local\Docker

Documentation: https://docs.docker.com/desktop/install/windows-install/#install-from-the-command-line

How can I change the location of docker images when using docker desktop on wsl2

  1. Stop docker

The WSL 2 docker-desktop-data vm disk image would normally reside in: %USERPROFILE%\AppData\Local\Docker\wsl\data\ext4.vhdx

Follow the following to relocate it to other drive/directory, with all existing docker data preserved (tested against Docker Desktop 2.3.0.4 (46911), and continued to work after updating the 3.1.0 (51484)):

First, shut down your docker desktop by right click on the Docker Desktop icon and select Quit Docker Desktop

Then, open your command prompt:

wsl --list -v You should be able to see, make sure the STATE for both is Stopped.(wsl --shutdown)

  NAME                   STATE           VERSION
* docker-desktop         Stopped         2
  docker-desktop-data    Stopped         2
Export docker-desktop-data into a file

wsl --export docker-desktop-data "D:\Docker\wsl\data\docker-desktop-data.tar" Unregister docker-desktop-data from wsl, note that after this, your ext4.vhdx file would automatically be removed (so back it up first if you have important existing image/container):

wsl --unregister docker-desktop-data Import the docker-desktop-data back to wsl, but now the ext4.vhdx would reside in different drive/directory:

wsl --import docker-desktop-data "D:\Docker\wsl\data" "D:\Docker\wsl\data\docker-desktop-data.tar" --version 2 Start the Docker Desktop again and it should work

You may delete the D:\Docker\wsl\data\docker-desktop-data.tar file (NOT the ext4.vhdx file) if everything looks good for you after verifying

doc here https://stackoverflow.com/questions/62441307/how-can-i-change-the-location-of-docker-images-when-using-docker-desktop-on-wsl2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment