준비 : EC2에 ssh로 접속한다.

 

Docker 설치

1. 패키지 업데이트 

sudo apt-get update

2. https관련 패키지 설치

sudo apt install apt-transport-https ca-certificates curl software-properties-common

3. docker repository 접근을 위한 gpg 키 설정

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

4. docker repository 등록

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"

5. 다시 패키지 업데이트

sudo apt update

6. 도커 설치

sudo apt-get install docker-ce docker-ce-cli containerd.io

7. 설치 확인

sudo docker --version

8. 도커로 hello-world 이미지 구동해봄

sudo docker run hello-world

9. 아래와 같은 메시지가 나오면 성공!

latest: Pulling from library/hello-world
719385e32844: Pull complete
Digest: sha256:926fac19d22aa2d60f1a276b66a20eb765fbeea2db5dbdaafeb456ad8ce81598
Status: Downloaded newer image for hello-world:latest

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-compose 설치

docker-compose를 standalone 방식으로 설치하는 방법이다.

 

1. Compose standalone을 다운로드하고 설치

sudo curl -SL https://github.com/docker/compose/releases/download/v2.20.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose

2. 설치한 파일에 실행권한 추가

sudo chmod +x /usr/local/bin/docker-compose

3. 어느 위치에서든 docker-compose 명령을 사용하고 싶으면, 아래 심볼릭 링크 추가

sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

4. docker-compose 버전 확인

sudo docker-compose -v

 

sudo 없이 docker 명령어 사용하기

1. 현재 사용자를 docker group에 포함

sudo usermod -aG docker ${USER}

사용자명이 ubuntu라면,

sudo usermod -aG docker ubuntu

2. 터미널 재시작 후 결과 확인(끝에 docker가 있는지 확인)

id -nG

 

참고

https://velog.io/@osk3856/Docker-Ubuntu-22.04-Docker-Installation

https://docs.docker.com/compose/install/standalone/

https://everydayyy.tistory.com/121

+ Recent posts