티스토리 뷰

Cloud/Cloud Native

Docker in centos

jacobbaek Jacob_baek 2019. 6. 7. 14:00

CentOS7에서 Docker 설치 및 실행법

CentOS7에서 Docker 설치 및 실행을 하는 방법을 간단히 기술한다.

[root@jenkins centos]# cat /etc/centos-release
CentOS Linux release 7.6.1810 (Core)

위와 같은 환경에서 설치를 진행하였다.

[root@jenkins centos]# yum install docker
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.mirror.moack.net
 * extras: centos.mirror.moack.net
 * updates: centos.mirror.moack.net
Resolving Dependencies
--> Running transaction check
---> Package docker.x86_64 2:1.13.1-96.gitb2f74b2.el7.centos will be installed
--> Processing Dependency: docker-common = 2:1.13.1-96.gitb2f74b2.el7.centos for package: 2:docker-1.13.1-96.gitb2f74b2.el7.centos.x86_64
--> Processing Dependency: docker-client = 2:1.13.1-96.gitb2f74b2.el7.centos for package: 2:docker-1.13.1-96.gitb2f74b2.el7.centos.x86_64

이후 docker 서비스를 재시작해본 결과 아래와 같은 에러가 발생하였다.

[root@jenkins centos]# systemctl start docker
Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.

[root@jenkins centos]# tail /var/log/messages
Jun  7 04:52:16 jenkins systemd: Started Docker Storage Setup.
Jun  7 04:52:16 jenkins systemd: Starting Docker Application Container Engine...
Jun  7 04:52:16 jenkins dockerd-current: time="2019-06-07T04:52:16.969455534Z" level=warning msg="could not change group /var/run/docker.sock to docker: group docker not found"
Jun  7 04:52:16 jenkins dockerd-current: time="2019-06-07T04:52:16.971288960Z" level=info msg="libcontainerd: new containerd process, pid: 12655"
Jun  7 04:52:18 jenkins dockerd-current: Error starting daemon: SELinux is not supported with the overlay2 graph driver on this kernel. Either boot into a newer kernel or disable selinux in docker (--selinux-enabled=false)
Jun  7 04:52:18 jenkins systemd: docker.service: main process exited, code=exited, status=1/FAILURE
Jun  7 04:52:18 jenkins systemd: Failed to start Docker Application Container Engine.
Jun  7 04:52:18 jenkins systemd: Unit docker.service entered failed state.
Jun  7 04:52:18 jenkins systemd: docker.service failed.

확인해본 결과 centos에서는 storage driver로 overlay2가 아닌 devicemapper를 사용하도록 해야 하였다. 아래 링크를 참고하기를 권장한다.
https://stackoverflow.com/questions/45461307/selinux-is-not-supported-with-the-overlay-graph-driver

[root@jenkins centos]# cat /etc/sysconfig/docker-storage
#DOCKER_STORAGE_OPTIONS="--storage-driver overlay2 "
DOCKER_STORAGE_OPTIONS="--storage-driver devicemapper "

overlay2의 경우 Ubuntu 의 AUFS를 기반으로 하고 있는데 Red Hat 및 CentOS의 경우 AUFS를 지원하지 않아 devicemapper를 사용하도록 하고 있다. 아래 링크에 좀더 상세히 나와있다. 참고할것을 권장한다.
https://ingeec.tistory.com/77

위와 같이 변경후 서비스 재시작시 정상적으로 재시작되고 동작함을 확인할 수 있다.

[root@jenkins centos]# systemctl restart docker
[root@jenkins centos]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
   Active: active (running) since Fri 2019-06-07 04:55:03 UTC; 49min ago
     Docs: http://docs.docker.com
 Main PID: 12714 (dockerd-current)
   CGroup: /system.slice/docker.service
           ├─12714 /usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=docker-runc --exec-opt native.cgroupdriver=systemd --userland-proxy-p...
           └─12720 /usr/bin/docker-containerd-current -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainer...

Jun 07 04:55:02 jenkins dockerd-current[12714]: time="2019-06-07T04:55:02.912942012Z" level=info msg="devmapper: Successfully created filesystem xfs on device docker-253:1-16818109-base"
Jun 07 04:55:02 jenkins dockerd-current[12714]: time="2019-06-07T04:55:02.992695613Z" level=info msg="Graph migration to content-addressability took 0.00 seconds"
Jun 07 04:55:02 jenkins dockerd-current[12714]: time="2019-06-07T04:55:02.993717359Z" level=info msg="Loading containers: start."
Jun 07 04:55:03 jenkins dockerd-current[12714]: time="2019-06-07T04:55:03.045208871Z" level=info msg="Firewalld running: false"
Jun 07 04:55:03 jenkins dockerd-current[12714]: time="2019-06-07T04:55:03.121608858Z" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon opti...d IP address"Jun 07 04:55:03 jenkins dockerd-current[12714]: time="2019-06-07T04:55:03.161344874Z" level=info msg="Loading containers: done."
Jun 07 04:55:03 jenkins dockerd-current[12714]: time="2019-06-07T04:55:03.173893692Z" level=info msg="Daemon has completed initialization"
Jun 07 04:55:03 jenkins dockerd-current[12714]: time="2019-06-07T04:55:03.173941585Z" level=info msg="Docker daemon" commit="b2f74b2/1.13.1" graphdriver=devicemapper version=1.13.1
Jun 07 04:55:03 jenkins dockerd-current[12714]: time="2019-06-07T04:55:03.185151400Z" level=info msg="API listen on /var/run/docker.sock"
Jun 07 04:55:03 jenkins systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.

CentOS8에서 Docker 사용

아래 링크에 자세히 나와있다.
참고로 yum 이 아닌 dnf로 repo 추가부터 설치를 진행한다.

dnf config-manager

문제상황과 해결법

만약 아래와 같은 문제를 겪고 있다면 CentOS의 환경을 다시한번 확인해보자.

[root@docker centos]# docker run -d -p 8080:8080 -p 50000:50000 --name jenkinsci jenkins/jenkins:lts
6f7fcdd5de26015e953715f156e54e1a712d584d84c8013b5ccd190430e97070
/usr/bin/docker-current: Error response from daemon: oci runtime error: container_linux.go:235: starting container process caused "process_linux.go:258: applying cgroup configuration for process caused \"Cannot set property TasksAccounting, or unknown property.\"".

위와 같은 문제를 겪고 있었을때의 환경은 아래와 같이 노후된 버전이었다.

[root@docker centos]# cat /etc/redhat-release && uname -msr
CentOS Linux release 7.3.1611 (Core) 
Linux 3.10.0-514.26.2.el7.x86_64 x86_64

하여 아래와 같이 update를 수행한후 다시 확인해본 결과 정상적으로 동작하였다.

[root@docker centos]# cat /etc/redhat-release && uname -msr
CentOS Linux release 7.6.1810 (Core) 
Linux 3.10.0-957.12.2.el7.x86_64 x86_64
[root@docker centos]# docker --version
Docker version 1.13.1, build b2f74b2/1.13.1
[root@docker centos]# docker run -d -p 8080:8080 -p 50000:50000 --name jenkinsci jenkins/jenkins:lts
020b678690429e05d737db0a5e68f1289edd0387c2053461e1f644a61649a754

Ubuntu 에서의 설치 및 사용법

만약 Ubuntu 16.04를 기반으로 설치를 진행하고자 할 경우 아래 링크를 참고하자. 아래링크에 잘설명이 되어있어 따로 기술하지는 않는다.

http://iamartin-gh.herokuapp.com/ubuntu-16-04-docker-install/

'Cloud > Cloud Native' 카테고리의 다른 글

minikube start in WSL2  (0) 2019.12.07
kubernetes troubleshooting  (0) 2019.11.14
Multi configured kubectl  (0) 2019.10.28
python application deploy with minikube  (0) 2019.09.28
Docker in centos  (0) 2019.06.07
application deploy using minikube  (0) 2017.09.04
댓글
댓글쓰기 폼