[container] wsl2 사용해서 docker 기동하기
저는 개인적으론 UI 환경에서 다루는게 익숙치 않다보니 도커 데스크톱보단
virtual box 설치 후 linux 올려서 docker 설치하는 방식으로 테스트를 진행했는데요.
제 PC의 경우 windows고 여기에 virtualbox를 올리고 리눅스 설치해서 일련의 과정을 진행하는게 조금 번거로웠습니다.
Windows PC에서 WSL을 활용하여 Ubuntu 22.04 를 올린 내용과 이슈 사항을 간단하게 공유드립니다.
wsl2에 docker 기동하기
1. wsl 사용하기
우선 CPU 가상화가 사용으로 되어 있는지 확인합니다. 작업관리자 > 성능 탭에서 확인가능합니다.

2. Linux용 WIndows 하위 시스템 활성화
제어판 > 프로그램 및 기능 에서 Windows 기능 켜기/끄기 > Linux용 Windows 하위 시스템 체크박스 선택후 확인
그 후 PC를 재기동해줍니다.
3. PC > Microsoft Store > Ubuntu 검색 후 원하는 버전 선택
저는 ubuntu 22.04.2 LTS 를 설치했습니다.
4. Docker 설치
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
# Add the repository to Apt sources:
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
5. 디버깅
그러나... 역시 한번에 되는게 없습니다.
docker 를 기동하려고 하니 부팅 프로세스가 systemd가 아닌 init이었네요.
System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is down |
이럴 땐 service docker start 를 해주면 되겠죠.
그러나... 또 안뜹니다. 이럴 땐 log를 보는게 좋겠죠.
로그 위치의 경우 /var/log/docker.log 입니다.

https://github.com/docker/for-linux/issues/1406
Failure to install and run Docker in WSL Ubuntu 22.04 (works in 20.04): "Cannot connect to the Docker daemon" · Issue #1406 ·
This is a bug report This is a feature request I searched existing issues before opening this one Steps to reproduce the behavior OS: Windows 10 21H2 Enabled features: Virtual Machine Platform, Win...
github.com
해당 url에서 확인해보시면 ubuntu 22.04 에서는 iptables-nft (nftables) 사용시 docker가 기동되지 않는 이슈가 있습니다.
그래서 iptables legacy로 변경해줘야 하는데요.
sudo update-alternatives --config iptables

1을 입력하고 엔터를 치면 됩니다.
다시 Windows로 돌아와서 powershell을 관리자 권한으로 실행 후 wsl --shutdown 을 해주세요~
만약 이렇게 해도 안되시는 분들은 설치된 linux가 wsl 2버전에서 동작되도록 설정되어 있는지 확인해보세요.
https://docs.docker.com/desktop/wsl/#enabling-docker-support-in-wsl-2-distros
Docker Desktop WSL 2 backend on Windows
Turn on the Docker WSL 2 backend and get to work using best practices, GPU support, and more in this thorough guide.
docs.docker.com
wsl.exe --set-version (distro name) 2
wsl.exe --set-default-version 2

6. 정리
단순 docker 테스트용으로 잘 쓸 것 같네요!
예전엔 hyper-v 어쩌구 뭐 해야할게 많았던 것 같은데 세상이 좋아진 것 같습니다.
감사합니다.