Tech

docker 시작하기

glqdlt 2017. 2. 3. 13:30

이 글은 도커 삽질한 내용을 정리한 것이다.

vm vs docker는 지난 포스트를 참고(http://glqdlt.tistory.com/244)하자


도커에는 CE와 EE가 있다, 이름만봐도 CE를 써야 할 느낌이 온다.

나는 우분투로 설치할터라 for 데비안 버전 가이드를 참고했다.

(https://store.docker.com/editions/community/docker-ce-server-debian?tab=description)

혹은 (https://docs.docker.com/engine/installation/linux/ubuntu/#install-using-the-repository)



#docker setup on ubuntu

레퍼런스 : https://docs.docker.com/engine/installation/linux/ubuntu/#install-using-the-repository


ubuntu 16.04.3 부터 apt-get 으로 자동 설치 지원한다 # 2017-09-11 확인

> apt-get install -y docker.io

근데 왜 이름이 docker.ce 가 아니고 .io 인지는 모르겠음 -_-;; (누가 선점했나?)



만약 16.04.3 이 아니거나, 설치를 수동으로 해야할 경우 아래를 참고.


> apt-get install -y apt-transport-https ca-certificates curl software-properties-common

> apt-get update -y

> curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add

> apt-key fingerprint 0EBFCD88

> add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

> apt-get update

> apt-get install -y docker-ce



#docker images install


> docker search ${image name}

> docker pull ${image name}


ex > docker search ubuntu

ex > docker pull ubuntu:latest




-v(--volume) 옵션으로 바인딩 할 때에는 host의 path에 무조건 아래처럼 권한 설정을 해주도록 한다. 
(편한 예시를 위해 무식한 방법으로 설정했다, 참고만 했으면 한다.)

권한 설정을 해주어야, 추후 docker 에서 지지고 볶고가 가능하다.

보통 root로 path를 설정하거나 mkdir 할 경우 root 소유가 되면, docker가 접근을 못한다 -_-;


chmod -R 775 ./{$dir}

chown -R ${user}:${user} ./{$dir}


ex > chmod -R 775 /home/glqdlt/my_docker/mysql_data

ex > chown -R glqdlt:glqdlt /home/glqdlt/my_docker/mysql_data


마지막으로 기본으로 내장되어있는 hello-world 컨테이너를 띄어 보자


> docker run -d hello-world


참고로 -d 옵션은 데몬 (백그라운드)으로 실행하겠다는 의미다, 저게 없으면 host 콘솔에서 컨테이너 안으로 진입이 되니 귀찮다


혹시 컨테이너 안으로 진입 시에 빠져나올 때에는 Ctrl+ P, Q 이다


--name 이나, --restart, --volume 과 같은 고급 기능들은 아래에서 참고하거나 hub의 레퍼런스를 읽고 썼으면 좋겠다.

(아규먼트 이름자체가 직설적이라 이해될거라 생각하고 설명은안한다.)


그리고 모든 것은 docker hub 에서 해당 images 의 벤더들이 메뉴얼을 제공해주니 그것만 보고 따라해도 무리없다.

https://hub.docker.com/help/

https://docs.docker.com/get-started/#test-docker-installation



아래 부터는 그냥 나를 위한 기록이다. 

기본적으로 docker-hub에 제작자들이 등록해놓은 READ ME 를 읽는 것이 가장 좋다.



#Redmine


예전처럼 Mysql을 데이터베이스로 쓰고 싶었으나, 최근버전에서 redmine image 와의 연동이 수월하지 않았다. (궁금해서 찾아보니 버그라고 한다,,, -_- 자세한 내역까진 안 봄.) 

그래서 postgresql 을 썼던 거고..  한방에 문제 해결했다.



1) postgres run..

> docker run -d --restart always -p 5432:5432 -v /home/archive/postgres_home:/var/lib/postgresql/data -e POSTGRES_PASSWORD=hello -e POSTGRES_USER=redmine --name postgres_jhun postgres


2) redmine sync

> docker run -d --restart always -p 8888:3000 --name redmine_jhun --link postgres_jhun:postgres redmine



#jenkins


docker run -d --restart always -p 18080:8080 -v /home/archive/jenkins_home:/var/jenkins_home --name jenkins_jhun jenkins


이 외에도 oracle, mysql, mariadb, maven nexus, gitlab-ce 등은 docker-hub 에서 직접 참고하여 설치하길 바람.

참고로 maven nexus 는 2인지 3인지를 잘 보고 pull run 해야한다. 두 놈이 기능 상에서도 차이가 있듯 설정도 서로 다르다. 

gitlab-ce는 메뉴얼이 docker hub 에 없고, gitlab (https://docs.gitlab.com/omnibus/docker/README.html) 에서 직접 제공하니 잘 찾아봐야 한다.



#oracle

> docker run --restart always -d -p 10001:8080 -p 10000:1521 -v /home/archive/oracle_home:/u01/app/oracle --name oracle_jhun sath89/oracle-xe-11g


official 이미지가 사용하기 까다로워서  https://hub.docker.com/r/sath89/oracle-xe-11g/ 이 이미지를 썼다.


(oracle 접속정보) 

hostname: localhost

port: 1521 -> 10000

sid: xe

username: system / password: oracle


#postgresql


> docker run -p 15432:5432 -e POSTGRES_USER=admin -e POSTGRES_PASSWORD=admin123 -v /home/archive/postgres_home_2/:/var/lib/postgresql/data --name postgres_jhun2 --restart always  postgres



# docker with pie도커에는 CE와 EE가 있다, 이름만봐도 CE를 써야 할 느낌이 온다.

나는 우분투로 설치할터라 for 데비안 버전 가이드를 참고했다.

(https://store.docker.com/editions/community/docker-ce-server-debian?tab=description)

혹은 (https://docs.docker.com/engine/installation/linux/ubuntu/#install-using-the-repository)



#docker setup on ubuntu

레퍼런스 : https://docs.docker.com/engine/installation/linux/ubuntu/#install-using-the-repository


ubuntu 16.04.3 부터 apt-get 으로 자동 설치 지원한다 # 2017-09-11 확인

> apt-get install -y docker.io

근데 왜 이름이 docker.ce 가 아니고 .io 인지는 모르겠음 -_-;; (누가 선점했나?)



만약 16.04.3 이 아니거나, 설치를 수동으로 해야할 경우 아래를 참고.


> apt-get install -y apt-transport-https ca-certificates curl software-properties-common

> apt-get update -y

> curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add

> apt-key fingerprint 0EBFCD88

> add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

> apt-get update

> apt-get install -y docker-ce



#docker images install


> docker search ${image name}

> docker pull ${image name}


ex > docker search ubuntu

ex > docker pull ubuntu:latest




-v(--volume) 옵션으로 바인딩 할 때에는 host의 path에 무조건 아래처럼 권한 설정을 해주도록 한다. 
(편한 예시를 위해 무식한 방법으로 설정했다, 참고만 했으면 한다.)

권한 설정을 해주어야, 추후 docker 에서 지지고 볶고가 가능하다.

보통 root로 path를 설정하거나 mkdir 할 경우 root 소유가 되면, docker가 접근을 못한다 -_-;


chmod -R 775 ./{$dir}

chown -R ${user}:${user} ./{$dir}


ex > chmod -R 775 /home/glqdlt/my_docker/mysql_data

ex > chown -R glqdlt:glqdlt /home/glqdlt/my_docker/mysql_data


그리고 모든 것은 docker hub 에서 해당 images 의 벤더들이 메뉴얼을 제공해주니 그것만 보고 따라해도 무리없다.

https://hub.docker.com/


아래 부터는 그냥 나를 위한 기록이다. 

기본적으로 docker-hub에 제작자들이 등록해놓은 READ ME 를 읽는 것이 가장 좋다.



#Redmine


예전처럼 Mysql을 데이터베이스로 쓰고 싶었으나, 최근버전에서 redmine image 와의 연동이 수월하지 않았다. (궁금해서 찾아보니 버그라고 한다,,, -_- 자세한 내역까진 안 봄.) 

그래서 postgresql 을 썼던 거고..  한방에 문제 해결했다.



1) postgres run..

> docker run -d --restart always -p 5432:5432 -v /home/archive/postgres_home:/var/lib/postgresql/data -e POSTGRES_PASSWORD=hello -e POSTGRES_USER=redmine --name postgres_jhun postgres


2) redmine sync

> docker run -d --restart always -p 8888:3000 --name redmine_jhun --link postgres_jhun:postgres redmine



#jenkins


docker run -d --restart always -p 18080:8080 -v /home/archive/jenkins_home:/var/jenkins_home --name jenkins_jhun jenkins


이 외에도 oracle, mysql, mariadb, maven nexus, gitlab-ce 등은 docker-hub 에서 직접 참고하여 설치하길 바람.

참고로 maven nexus 는 2인지 3인지를 잘 보고 pull run 해야한다. 두 놈이 기능 상에서도 차이가 있듯 설정도 서로 다르다. 

gitlab-ce는 메뉴얼이 docker hub 에 없고, gitlab (https://docs.gitlab.com/omnibus/docker/README.html) 에서 직접 제공하니 잘 찾아봐야 한다.



#oracle

> docker run --restart always -d -p 10001:8080 -p 10000:1521 -v /home/archive/oracle_home:/u01/app/oracle --name oracle_jhun sath89/oracle-xe-11g


official 이미지가 사용하기 까다로워서  https://hub.docker.com/r/sath89/oracle-xe-11g/ 이 이미지를 썼다.


(oracle 접속정보) 

hostname: localhost

port: 1521 -> 10000

sid: xe

username: system / password: oracle


#postgresql


> docker run -p 15432:5432 -e POSTGRES_USER=admin -e POSTGRES_PASSWORD=admin123 -v /home/archive/postgres_home_2/:/var/lib/postgresql/data --name postgres_jhun2 --restart always  postgres



#docker with pie


산딸기의 ARM 아키텍쳐는 docker와 친하지 않다.

무식하다 보니 단순하게 라즈비안 때문이라고 생각하고 ubuntu-mate 로 새로 설치해서 시도해보았는 데..

docker 를 겨우겨우 깔았더니, 이미지가 ARM 을 지원하지 않아서 뻑킹했다.



이를 해결하고자 하는 친구들이 있는 데, docker priot 이라는 친구들이다. 

(https://blog.hypriot.com/getting-started-with-docker-on-your-arm-device/)


한번 찾아보고 적용기를 블로깅 해보겠다 -_-