2015년 9월 24일 목요일

MUG 4차 OFF 미팅때 김영하님이 발표하신 자료를 바탕으로 제 환경에서 Docker를 이용해서 MySQL 이미지를 가지고 오는 걸 테스트해봤습니다. 생각보다 쉽게 잘 되네요.
제 환경은 Virtual Box위에  Oracle Linux 6.6를 올려서 테스트했습니다. 

우선 Docker를 설치하겠습니다.

[root@smdomain /]yum update
 ................
 ypbind.x86_64 3:1.20.4-31.el6           
  yum.noarch 0:3.2.29-69.0.1.el6                                                                     
  yum-rhn-plugin.noarch 0:0.9.1-58.0.3.el6                                                           

Complete!
[root@smdomain /]# yum install -y curl
Loaded plugins: refresh-packagekit, security, ulninfo
Setting up Install Process
Package curl-7.19.7-46.el6.x86_64 already installed and latest version
Nothing to do

[root@smdomain /]# curl -sSL https://get.docker.com/ | sh
+ sh -c 'sleep 3; yum -y -q install docker-engine'
warning: rpmts_HdrFromFdno: Header V4 RSA/SHA1 Signature, key ID 2c52609d: NOKEY
Importing GPG key 0x2C52609D:
 Userid: "Docker Release Tool (releasedocker) <docker@docker.com>"
 From  : https://yum.dockerproject.org/gpg

If you would like to use Docker as a non-root user, you should now consider
adding your user to the "docker" group with something like:

  sudo usermod -aG docker your-user

Remember that you will have to log out and back in for this to take effect!


[root@smdomain /]# service docker start
Starting cgconfig service:                                 [  OK  ]
Starting docker:                                       [  OK  ]

[root@smdomain /]# vi /etc/sysconfig/docker 
아래 내용을 추가 후 저장
OPTIONS='
-s overlay \
--dns 8.8.8.8 \
--dns 8.8.4.4 \
-H tcp://127.0.0.1:4243 \
-H unix:///var/run/docker.sock \
--dns-search google-public-dns-a.google.com'

[root@smdomain /]# service docker stop
Stopping docker:                                           [  OK  ]
[root@smdomain /]# service docker start
Starting docker:                                       [  OK  ]
[root@smdomain /]#

Docker 설치와 설정이 완료되면 MySQL 5.7.8 버전을 가지고 옵니다.  mysql로만 주면 전체버전을 가져와서 시간이 오래 걸립니다. 그래서 버전을 명시해주시는게 편합니다. 그리고 저는 진행 중 "Layer already being pulled by another client. Waiting."으로 나와서 한참 기다려도 안되서 VM을 다시 시작했더니 잘 되더라구요.
[root@smdomain /]# docker pull mysql:5.7.8

5.7.8: Pulling from library/mysql
ba249489d0b6: Pull complete
19de96c112fc: Pull complete
2e32b26a94ed: Pull complete
637386aea7a0: Pull complete
f40aa7fe5d68: Pull complete
ca21348f3728: Pull complete
0ad76278b41a: Pull complete
144338480fda: Pull complete
ae4a07c87e1e: Pull complete
221780071ced: Verifying Checksum
d28d836f9940: Download complete
dadfa90a4b79: Download complete
6c1abd0b82b2: Download complete
7951e766c75c: Download complete
e371d089a94c: Download complete
0e269f9884d9: Download complete 

가지고 온 MySQL이미지를 이용해 MySQL을 실행하는 부분은 아래 URL내용 참고해 진행합니다.
https://hub.docker.com/_/mysql/

MYSQL_ROOT_PASSWORD=my-secret-pw 를 이용해서 mysql의 root 계정의 비밀번호를 설정합니다.
[root@smdomain /]# docker run --name mysql578 \
> -e MYSQL_ROOT_PASSWORD=mysql -d mysql:5.7.8

bb5d732f222edce9ddce834b5a07cd892df0b7c09d09d6a586f89582322382be
[root@smdomain /]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
bb5d732f222e        mysql:5.7.8         "/entrypoint.sh mysql"   16 seconds ago      Up 15 seconds       3306/tcp            mysql578
[root@smdomain /]#


MySQL Client로 접속합니다.
[root@smdomain /]# docker run -it --link mysql578:mysql --rm mysql:5.7.8 \
> sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"3306" -uroot -p'

Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.8-rc MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)
* 참고 URL :
- https://hub.docker.com/_/mysql/
- http://slides.com/fermat39/mysqljsonfunctions#/0/25

댓글 없음:

댓글 쓰기