Menu

[linux] 리눅스 서버에 도커(Docker) 설치

이전에 linux 를 설치 해 보았다.

이 서버에 Docker 를 설치해 보고자 한다.

root 계정으로 설치할 것이며 yum 을 이용해 설치를 진행할 것이다.


yum update

설치를 진행하기 전 패키지를 설치할땐 최신버전을 설치하는게 좋으므로 yum 을 update 한다.

> yum update -y

업데이트 할게 많다... 337개나 되네 ㄷㄷ..

관련 패키지 설치

> yum install -y yum-utils device-mapper-persistent-data lvm2

Docker 설치 준비

> yum-config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo

위 명령어를 실행하고 docker 를 설치할 경우(공식 메뉴얼대로 했는데 404 라니!!)

image.png

이런 에러가 나타난다. 위 주소중 rhelcentos 로 변경한다.
(https://download.docker.com/linux/centos/7/x86_64/stable/repodata/repomd.xml 이 링크에 매핑된 파일이 있는지 확인!)

> yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

이 후에 yum install docker-ce 명령어를 날리면 오류가 날 것이다.
버전 종속성 오류로 보여진다.

image.png

Docker 설치

오류를 해결하기 위하여 http://mirror.centos.org/centos/7/extras/x86_64/Packages/ 에 접속하여 관련 패키지를 다운 받았다.

  • 패키지 목록

> yum install -y http://mirror.centos.org/centos/7/extras/x86_64/Packages/slirp4netns-0.4.3-4.el7_8.x86_64.rpm
> yum install -y http://mirror.centos.org/centos/7/extras/x86_64/Packages/fuse3-libs-3.6.1-4.el7.x86_64.rpm
> yum install -y http://mirror.centos.org/centos/7/extras/x86_64/Packages/fuse3-devel-3.6.1-4.el7.x86_64.rpm
> yum install -y http://mirror.centos.org/centos/7/extras/x86_64/Packages/fuse3-3.6.1-4.el7.x86_64.rpm
> yum install -y http://mirror.centos.org/centos/7/extras/x86_64/Packages/fuse-overlayfs-0.7.2-6.el7_8.x86_64.rpm

구글링 중 container-selinux 도 설치하는 블로그를 보았다.
바로 실행해보자!

> yum install -y http://mirror.centos.org/centos/7/extras/x86_64/Packages/container-selinux-2.107-3.el7.noarch.rpm

(해당 블로그에선 container-selinux버전 확인 및 링크 복사 하라고 나와 있다.)

image.png

이제 설치 명령어를 실행하면...

> yum install -y docker-ce

image.png

드디어 설치가 되었다!!!

docker 설치 확인

설치 확인에 앞서 docker를 실행하자

> systemctl start docker

서버가 재부팅 되도 바로 시작하도록 설정해주자

> systemctl enable docker

docker version 명령어로 확인해보자!

image.png

설치 이후 - Remote Docker 사용

다른 docker 서버를 사용할 때 2375 포트를 연동하여 사용 했었는데 새로 설치한 docker 서버를 접근하려보니 2375 포트가 열려있지 않았었다.
원인을 찾다보니 /usr/lib/systemd/system/docker.service 파일 중 ExecStart 항목에 설정을 변경 해줬어야 했다.


...

[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H fd:// -H 0.0.0.0:2375 --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always

...

dockerddocker daemon, -Hhost 이며 자신이 docker daemon의 호스트로 사용할 IP, Port 를 작성한다.
위 설정 중 0.0.0.0:2375 는 2375 포트를 사용하는 모든 IP 를 허용 한다는 뜻이다.
0.0.0.0:2375를 Host로서 docker daemon을 실행하도록 하는 것이다.

설정 변경 후 알 ㅐ명령어를 통해서 docker daemon 을 적용 시킨다.

> sudo systemctl daemon-reload
> sudo systemctl restart docker.service

마무리

docker 설치가 생각보다 힘들었다.
설치 오류를 찾던 중 OS 를 CentOS v7.9 버전으로 설치하였더니 이런 이슈가 없었다는 글을 보았는데
현재 내가 가지고 있는 버전은 v7.5 가 최신이고 (ㅠㅠ) OS 를 다시 깔기도 시간 아깝다라는 생각이 들었다.
(v7.9 를 추가하고 다시 설치하는게 더 빨랐을지도..)


참조

도움