[참고 사이트]
- Rocky Linux 9 에서 Docker 설치하기
1. 우분투(Ubuntu 20.04.6 LTS)에 Docker 설치
(1) Docker Engine 설치
① 시스템 패키지 업데이트
ubuntu@ubuntu:~$ sudo apt-get update
② 필요한 패키지 설치
ubuntu@ubuntu:~$ sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
- apt-transport-https : 패키지 관리자가 https를 통해 데이터 및 패키지에 접근할 수 있도록 한다.
- ca-certificates : ca-certificate는 certificate authority에서 발행되는 디지털 서명. SSL 인증서의 PEM 파일이 포함되어 있어 SSL 기반 앱이 SSL 연결이 되어있는지 확인할 수 있다.
- curl : 특정 웹사이트에서 데이터를 다운로드 받을 때 사용
- gnupg-agent : GnuPG key를 관리하는 agent
- software-properties-common : *PPA를 추가하거나 제거할 때 사용한다.
③ Docker의 공식 GPG키를 추가
ubuntu@ubuntu:~$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
[curl 명령어의 옵션]
- f : HTTP 요청 헤더의 contentType을 multipart/form-data로 보낸다.
- s : 진행 과정이나 에러 정보를 보여주지 않는다.(–silent)
- S : SSL 인증과 관련있다고 들었는데, 정확히 아시는 분 있다면 댓글 부탁!
- L : 서버에서 301, 302 응답이 오면 redirection URL로 따라간다.
- apt-key : apt가 패키지를 인증할 때 사용하는 키 리스트를 관리한다. 이 키를 사용해 인증된 패키지는 신뢰할 수 있는 것으로 간주한다. add 명령어는 키 리스트에 새로운 키를 추가하겠다는 의미이다.
④ Docker의 공식 apt 저장소(repository)를 추가
ubuntu@ubuntu:~$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
- add-apt-repository : PPA 저장소를 추가해준다. apt 리스트에 패키지를 다운로드 받을 수 있는 경로가 추가된다.
⑤ 시스템 패키지 업데이트
ubuntu@ubuntu:~$ sudo apt-get update
⑥ Docker 설치
ubuntu@ubuntu:~$ sudo apt-get install docker-ce docker-ce-cli containerd.io
⑦ 설치된 Docker 버전 확인
ubuntu@ubuntu:~$ docker --version Docker version 26.1.1, build 4cf5afa
⑧ Docker 설치 확인
ubuntu@ubuntu:~$ sudo systemctl status docker ● docker.service - Docker Application Container Engine Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2024-05-02 07:50:55 UTC; 12s ago ...
⑨ Docker 실행
자동 설치 스크립트로 다운받았던 사람들은 hello-world 이미지 파일이 이미 있으니 다시 다운 받지 않아도 된다.
- docker pull은 도커 허브 사이트에서 이미지 파일을 가져온다.
ubuntu@ubuntu:~$ sudo docker pull hello-world Using default tag: latest latest: Pulling from library/hello-world c1ec31eb5944: Pull complete Digest: sha256:a26bff933ddc26d5cdf7faa98b4ae1e3ec20c4985e6f87ac0973052224d24302 Status: Downloaded newer image for hello-world:latest docker.io/library/hello-world:latest
- 내 시스템에 어떤 이미지들이 있는지 확인하려면 docker images를 활용
ubuntu@ubuntu:~$ sudo docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest d2c94e258dcb 12 months ago 13.3kB
- 컨테이너 실행
ubuntu@ubuntu:~$ 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/
- 컨테이너 확인하기
ubuntu@ubuntu:~$ sudo docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7012affd3ff3 hello-world "/hello" 25 seconds ago Exited (0) 25 seconds ago blissful_tesla
- 컨테이너 삭제
ubuntu@ubuntu:~$ sudo docker rm 7012affd3ff3
(2) Docker Compose 설치
① 도커 컴포즈 설치
ubuntu@ubuntu:~$ sudo curl -L "https://github.com/docker/compose/releases/download/v2.27.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
- 최신 버전 확인 : https://github.com/docker/compose/releases
- 버전을 변경하고 싶으면 가운데에 있는 v2.5.0을 변경하면 됩니다.
② 도커 컴포즈 권한 부여
ubuntu@ubuntu:~$ sudo chmod +x /usr/local/bin/docker-compose
③ 심볼릭 링크 연결
ubuntu@ubuntu:~$ sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
④ 버전 확인
ubuntu@ubuntu:~$ docker-compose --version Docker Compose version v2.27.0
2. 로키(Rocky Linux 9.3)에 Docker 설치
(1) Docker Engine 설치
① 시스템 패키지 업데이트
[rocky@localhost ~]$ sudo dnf -y update
② Docker의 공식 dnf 저장소(repository)를 추가
[rocky@localhost ~]$ sudo dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
③ Docker 설치
[rocky@localhost ~]$ sudo dnf -y install docker-ce docker-ce-cli containerd.io docker-compose-plugin
④ Docker 서비스 시작 및 활성화
[rocky@localhost ~]$ sudo systemctl --now enable docker
⑤ 설치된 Docker 버전 확인
[rocky@localhost ~]$ docker --version Docker version 26.1.1, build 4cf5afa
⑥ Docker 설치 확인
[rocky@localhost ~]$ sudo systemctl status docker ● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; preset: disabled) Active: active (running) since Thu 2024-05-02 17:18:25 KST; 10s ago ...
⑦ Docker 실행
- docker pull은 도커 허브 사이트에서 이미지 파일을 가져온다.
[rocky@localhost ~]$ sudo docker pull hello-world Using default tag: latest latest: Pulling from library/hello-world c1ec31eb5944: Pull complete Digest: sha256:a26bff933ddc26d5cdf7faa98b4ae1e3ec20c4985e6f87ac0973052224d24302 Status: Downloaded newer image for hello-world:latest docker.io/library/hello-world:latest
- 내 시스템에 어떤 이미지들이 있는지 확인하려면 docker images를 활용
[rocky@localhost ~]$ sudo docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest d2c94e258dcb 12 months ago 13.3kB
- 컨테이너 실행
[rocky@localhost ~]$ 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/
- 컨테이너 확인하기
[rocky@localhost ~]$ sudo docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ed75eefc79ef hello-world "/hello" 46 seconds ago Exited (0) 45 seconds ago gallant_keldysh
- 컨테이너 삭제
[rocky@localhost ~]$ sudo docker rm ed75eefc79ef
(2) Docker Compose 설치
① 도커 컴포즈 설치
[rocky@localhost ~]$ sudo curl -L "https://github.com/docker/compose/releases/download/v2.27.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
- 최신 버전 확인 : https://github.com/docker/compose/releases
- 버전을 변경하고 싶으면 가운데에 있는 v2.5.0을 변경하면 됩니다.
② 도커 컴포즈 권한 부여
[rocky@localhost ~]$ sudo chmod +x /usr/local/bin/docker-compose
③ 심볼릭 링크 연결
[rocky@localhost ~]$ sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
④ 버전 확인
[rocky@localhost ~]$ docker-compose --version Docker Compose version v2.27.0
728x90
반응형
'Docker' 카테고리의 다른 글
[Docker] 도커 네트워크 구조 (0) | 2025.02.19 |
---|---|
[Docker] 도커 컨테이너 - 라이프사이클 및 명령어 (0) | 2025.02.19 |
[Docker] 윈도우에 Docker 설치(Home 포함) (0) | 2025.02.19 |
[Docker] 도커 아키텍처 및 흐름 (0) | 2025.02.19 |
[Docker] 도커 개념 설명 | 도커는 왜 사용하는 걸까? (0) | 2025.02.19 |