install docker in WSL2
11 Mar 2022이전 포스트: WSL 설치하기
참고: docker docs
저장소 설정
- HTTPS를 통해 리포지토리를 사용할 수 있도록 패키지 인덱스를 업데이트하고 apt패키지를 설치
sudo apt-get update sudo apt-get install \ ca-certificates \ curl \ gnupg \ lsb-release
- Docker의 공식 GPG 키 추가:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
도커 엔진 설치
- apt패키지 인덱스를 업데이트하고 최신 버전의 Docker Engine 및 containerd를 설치(또는 특정 버전을 설치-공식 docs 참고)
sudo apt-get update sudo apt-get install docker-ce docker-ce-cli containerd.io
도커 설치 확인(오류 발생)
$ sudo docker version
Client: Docker Engine - Community
Version: 20.10.13
API version: 1.41
Go version: go1.16.15
Git commit: a224086
Built: Thu Mar 10 14:07:51 2022
OS/Arch: linux/amd64
Context: default
Experimental: true
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
$ systemctl status
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
오류 해결(아래 명령어 실행)
1번 방법
sudo -b unshare --pid --fork --mount-proc /lib/systemd/systemd --system-unit=basic.target
참고) https://askubuntu.com/questions/1379425/system-has-not-been-booted-with-systemd-as-init-system-pid-1-cant-operate
2번 방법
sudo apt-get update && sudo apt-get install -yqq daemonize dbus-user-session fontconfig
sudo daemonize /usr/bin/unshare --fork --pid --mount-proc /lib/systemd/systemd --system-unit=basic.target
exec sudo nsenter -t $(pidof systemd) -a su - $LOGNAME
snap version
참고) https://gist.github.com/alyleite/ca8b10581dbecd722d9dcc35b50d9b2b
$ sudo docker version
Client: Docker Engine - Community
Version: 20.10.13
API version: 1.41
Go version: go1.16.15
Git commit: a224086
Built: Thu Mar 10 14:07:51 2022
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.13
API version: 1.41 (minimum version 1.12)
Go version: go1.16.15
Git commit: 906f57f
Built: Thu Mar 10 14:05:44 2022
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.5.10
GitCommit: 2a1d4dbdb2a1030dc5b01e96fb110a9d9f150ecc
runc:
Version: 1.0.3
GitCommit: v1.0.3-0-gf46b6ba
docker-init:
Version: 0.19.0
GitCommit: de40ad0
postgresql 설치
docker run --name rest -p 5432:5432 -e POSTGRES_PASSWORD=pass -d postgres
sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
389ad2d36ff3 postgres "docker-entrypoint.s…" About a minute ago Up About a minute 0.0.0.0:5432->5432/tcp, :::5432->5432/tcp rest
postgresql 실행
- exec : 실행 / -i : 인터렉티브 / -t : 컨테이너 타겟 / bash : 어떤 명령어를 실행할지
sudo docker exec -i -t rest bash
postgresql 연결하기(컨테이너 안으로 들어가기)
- 데이터베이스이름, 기본유저이름이 postgres
psql -d postgres -U postgres
Query Databases
\l
Query Tables
\dt
Quit
\q
컨테이너 실행하기
sudo docker start rest