I am trying to create microservice Docker images on a Windows machine. How do I install and use Docker using Windows Subsystem for Linux v2 (WSL2)?

 채택된 답변

MathWorks Support Team
MathWorks Support Team 2025년 6월 18일
편집: MathWorks Support Team 2025년 6월 18일

1 개 추천

To use Docker with WSL2, you should have WSL2 installed. You can list your installed Linux distributions and check the version of WSL each is set to by entering below command in PowerShell or Windows Command Prompt. 
wsl -l -v
If WSL2 is not installed, you can install WSL2 using below command. For more detailed instructions, please refer to https://learn.microsoft.com/windows/wsl/install.
wsl --install
After installation, start a new WSL2 session and you will be asked to create a User Name and Password for your Linux distribution. Follow the prompt for instructions.
wsl -d Ubuntu
Next, complete the following steps. The instructions assume you are using an Ubuntu or Debian distribution. For other Linux distributions, see https://docs.docker.com/engine/install/.
Update software packages.
sudo apt update && sudo apt upgrade
Install Docker dependencies.
sudo apt install --no-install-recommends apt-transport-https ca-certificates curl gnupg2
Switch the firewall to legacy iptables.
sudo update-alternatives --set iptables /usr/sbin/iptables-legacy
If you receive error "update-alternatives: error: no alternatives for iptables". Run below commands to install iptables first. Then retry above step.
sudo apt update sudo apt install iptables
Download the Docker OpenPGP signing key for your distribution.
. /etc/os-release curl -fsSL https://download.docker.com/linux/${ID}/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/docker-archive-keyring.gpg
Add the Docker package repository to /etc/apt/sources.list.d.
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/${ID} ${VERSION_CODENAME} stable" \ | sudo tee /etc/apt/sources.list.d/docker.list
Install Docker.
sudo apt update sudo apt install docker-ce docker-ce-cli containerd.io
Add the current user to the docker group.
sudo usermod -aG docker $USER
Restart the WSL2 session by closing and reopening your WSL2 terminal to apply group changes.
Start Docker Daemon.
sudo dockerd
In a MATLAB command window, confirm that MATLAB detects your Docker installation.
[~,msg] = system('wsl docker version')

댓글 수: 1

Jeremy Huard
Jeremy Huard 2022년 11월 23일
@Mohamad The creation of microservices on Windows is only supported since R2022b. R2022a only supports Linux: https://www.mathworks.com/help/compiler_sdk/release-notes.html

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by