공부/Docker
Docker 설치법
G.K.
2023. 9. 15. 16:03
마인크래프트 서버를 독커로 돌려보려고 한다. GUI 버전보다 가벼울테고...
https://docs.docker.com/engine/install/ubuntu/
Install Docker Engine on Ubuntu
Jumpstart your client-side server applications with Docker Engine on Ubuntu. This guide details prerequisites and multiple methods to install.
docs.docker.com
구버전 삭제하기
for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove $pkg; done
/var/lib/docker/ 에 있는 정보는 삭제되지 않을수도 있다고 한다.
sudo apt-get purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd
위 명령어로 Docker Engine 까지 삭제해주자.
Repository 설정
# Add Docker's official GPG key:
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
위 코드는 공식 GPG 키를 추가하며, 아래 코드는 Apt list에 docker repository를 추가한다.
docker 패키지 설치
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
docker 설치 확인
sudo docker run hello-world
아래와 같은 메세지가 출력되는것을 확인하여 잘 설치되었는지 확인하자.
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
그러나 문제가 있다. docker 명령어를 쓰려면 계속 sudo 명령어로 루트 권한으로 써야 하는데 너무 번거롭다. 그래서 낼름 받아올것이다.
sudo groupadd docker
sudo usermod -aG docker $USER
이후 재시작을 해주면 루트 권한 이외 일반 사용자 권한으로도 사용 가능하다.