포스트

Docker - ubuntu 22.04에 설치하기

OS info : Ubuntu 22.04.4 LTS


Docker Engine 설치

Install Docker Engine on Ubuntu
https://docs.docker.com/engine/install/ubuntu/

위 사이트를 참고하며 ubuntu 22.04 LTS 버전에 docker engine을 설치!


1. apt docker repository 설정

docker engine을 처음 설치하는 경우 apt docker repository를 설정해야 설치할 수 있다.

Add Docker’s official GPG key

1
2
3
4
5
sudo apt-get update \
&& sudo apt-get install ca-certificates curl \
&& sudo install -m 0755 -d /etc/apt/keyrings \
&& sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc \
&& sudo chmod a+r /etc/apt/keyrings/docker.asc

Add the repository to Apt sources

1
2
3
4
5
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] 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


2. docker 설치

1
 sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
  • 설치 초반에 Do you want to continue? [Y/n] 라며 계속 진행하겠냐고 묻는 과정이 있으므로 지켜봐야 한다.

내 경우 설치 완료까지 2분 소요되었다.



docker 동작 테스트

설치가 되었다면 도커 버전정보를 조회하여 잘 설치되었는지 확인한다.

1
2
docker -v
# > Docker version 27.0.2, build 912c1dd


nginx 웹 서버 컨테이너 실행해보기

1. nginx 이미지 다운받은 후 인스턴스 실행

1
2
3
4
5
# nginx 컨테이너 생성 & 실행
docker run -d --name test-web-server -p 99:80 nginx

# container 활동 확인
docker ps 
  • 내 경우 80포트를 사용하고 있기 때문에 외부 접근 포트를 99로 변경


2. nginx 서버 실행 확인

ping 명령어로는 조회할 host의 포트 번호를 지정할 수 없으므로
curl 명령어를 이용하여 99 포트로 nginx 서버가 동작하고있는지 확인한다.

1
curl http://localhost:99 
  • 명령어 실행 결과로 아래와 같은 코드가 나타나면 성공!
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    
      <!DOCTYPE html>
      <html>
      <head>
      <title>Welcome to nginx!</title>
      <style>
      html { color-scheme: light dark; }
      body { width: 35em; margin: 0 auto;
      font-family: Tahoma, Verdana, Arial, sans-serif; }
      </style>
      </head>
      <body>
      <h1>Welcome to nginx!</h1>
      <p>If you see this page, the nginx web server is successfully installed and
      working. Further configuration is required.</p>
    
      <p>For online documentation and support please refer to
      <a href="http://nginx.org/">nginx.org</a>.<br/>
      Commercial support is available at
      <a href="http://nginx.com/">nginx.com</a>.</p>
    
      <p><em>Thank you for using nginx.</em></p>
      </body>
      </html>
    


3. 인스턴스 삭제 및 nginx 이미지 삭제

1
2
3
4
5
6
7
8
9
10
11
12
# 컨테이너 및 이미지 삭제
docker rm -f test-web-server && docker rmi nginx

# 컨테이너 조회하여 삭제됨을 확인
docker ps -a

# 이미지 조회하여 삭제됨을 확인
docker images

# curl 명령어를 이용하여 찾을 수 없음을 확인
curl http://localhost:99
# > curl: (7) Failed to connect to localhost port 99 after 0 ms: Connection refused


이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.