컨테이너 가상화(Docker 설치/리눅스/centos)
1. 저장소 추가
■ 리포지토리 저장소 추가
[root@localhost ~]# dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
다음 위치에서 레포 추가 : https://download.docker.com/linux/centos/docker-ce.repo
■ yum-utils 패키지 설치
[root@localhost ~]# yum install -y yum-utils
[root@localhost ~]# yum list yum-utils
마지막 메타 데이터 만료 확인 : 1:43:52 전에 2021년 02월 09일 (화) 오후 03시 15분 24초.
설치된 패키지
yum-utils.noarch 4.0.17-5.el8 @BaseOS
2. 도커 설치
■ 도커 설치
[root@localhost ~]# yum install -y docker-ce
3. 도커 실행
■ 도커 버전 확인
[root@localhost ~]# docker version
Server: Docker Engine - Community
Engine:
Version: 20.10.3
API version: 1.41 (minimum version 1.12)
Go version: go1.13.15
Git commit: 46229ca
Built: Fri Jan 29 14:31:25 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.3
GitCommit: 269548fa27e0089a8b8278fc4fc781d7f65a939b
runc:
Version: 1.0.0-rc92
GitCommit: ff819c7e9184c13b7c2607fe6c30ae19403a7aff
docker-init:
Version: 0.19.0
GitCommit: de40ad0
■ 부팅시 자동실행
[root@localhost ~]# systemctl enable docker
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.
■ 서비스 실행
[root@localhost ~]# systemctl start docker
■ 서비스 상태 확인
[root@localhost ~]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2021-02-03 10:56:08 KST; 6 days ago
4. iptables 설치
■ 포트포워딩을 위한 iptables 설치
[root@localhost ~]# yum install –y iptables-services
Transaction Summary
===============================================================================================================================================================================================
설치 1 Package
업그레이드 4 Packages
Total download size: 906 k
패키지 다운로드중:
(1/5): iptables-ebtables-1.8.4-15.el8_3.3.x86_64.rpm 1.4 MB/s | 71 kB 00:00
(2/5): iptables-services-1.8.4-15.el8_3.3.x86_64.rpm 347 kB/s | 62 kB 00:00
(3/5): iptables-libs-1.8.4-15.el8_3.3.x86_64.rpm 774 kB/s | 106 kB 00:00
(4/5): libnftnl-1.1.5-4.el8.x86_64.rpm 1.6 MB/s | 83 kB 00:00
(5/5): iptables-1.8.4-15.el8_3.3.x86_64.rpm 2.1 MB/s | 584 kB 00:00
---------------------------------------------------------------------------------------------------------------------------------------------------------------------성공적으로 가져온 키
트랜잭션 점검 실행 중
트랜잭션 검사가 성공했습니다.
트랜잭션 테스트 실행 중
트랜잭션 테스트가 완료되었습니다.
거래 실행 중
준비 중입니다 :
설치됨:
iptables-services-1.8.4-15.el8_3.3.x86_64
완료되었습니다!
5. iptables 도커체인 등록
■ 컨테이너 실행 시 오류 발생
[root@localhost ~]# docker run -d -i -t --name="tomcat-test" -p 8080:8080 tomcat:latest
a5ae2b0ad6b4f700668a60c9ac99c6242d6a15e8f701a54665ccc1ab5b93ff9d
docker: Error response from daemon: driver failed programming external connectivity on endpoint tomcat-test (77960ef35eb71edeef3c6488472bab8202ca0b4cdf60555013e5af7b8b35360e): (iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 8080 -j DNAT --to-destination 172.17.0.2:8080 ! -i docker0: iptables: No chain/target/match by that name.
(exit status 1)).
☞ iptables 에 도커 체인을 등록하여 오류 해결
■ iptables 도커 체인 등록
[root@localhost ~]# iptables -t nat -N DOCKER
[root@localhost ~]# iptables -t nat -A PREROUTING -m addrtype --dst-type LOCAL -j DOCKER
[root@localhost ~]# iptables -t nat -A PREROUTING -m addrtype --dst-type LOCAL ! --dst 127.0.0.0/8 -j DOCKER
■ iptables 설정 저장
[root@localhost ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
■ iptables 재시작(설정 반영)
[root@localhost ~]# service iptables restart
Redirecting to /bin/systemctl restart iptables.service
'도커(Docker)' 카테고리의 다른 글
도커 명령어 (0) | 2021.06.21 |
---|
댓글