随着Docker和CoreOS的火爆,服务容器化将称为一种趋势,从而降低操作系统和应用程序的耦合度。本文在ubuntu 14.10下对MySQL和Redis的docker images进行简单测试。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
#---------------------------------------- #1. 安装网桥工具和docker apt-get install bridge-utils apt-get install docker.io #---------------------------------------- #2. 使用 brctl show 来查看网桥和端口连接信息。Docker 默认指定了 docker0 接口 的 IP 地址和子网掩码,可以自定义这个网桥和IP地址(需要禁用生成树)。 brctl show bridge name bridge id STP enabled interfaces docker0 8000.56847afe9799 no ip addr show docker0 8: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default link/ether 56:84:7a:fe:97:99 brd ff:ff:ff:ff:ff:ff inet 10.0.42.1/16 scope global docker0 valid_lft forever preferred_lft forever inet6 fe80::5484:7aff:fefe:9799/64 scope link valid_lft forever preferred_lft forever #3. pull images docker pull ubuntu:14.04 docker pull redis:2.8.9 # at URL https://registry.hub.docker.com/_/redis/ docker pull tutum/mysql:5.6 # at URL https://github.com/tutumcloud/tutum-docker-mysql docker pull node:0.11.14 # at URL https://registry.hub.docker.com/_/node/ docker pull rocker/r-base #---------------------------------------- #4. starting redis #data volume mkdir /var/lib/redis #mount data volume, map port 6379, daemonized docker run --name redis-s01 -d -v /var/lib/redis:/data -p 6379:6379 redis redis-server --appendonly yes --dir /data #logs docker logs 4ff42963642151b0733559bfa39465d3e2bee99708a4e6d0d2ec2bdaa80d7c3c _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 2.8.19 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in stand alone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 1 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' [1] 29 Dec 02:02:00.698 # Server started, Redis version 2.8.19 [1] 29 Dec 02:02:00.698 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect. [1] 29 Dec 02:02:00.698 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled. [1] 29 Dec 02:02:00.698 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. [1] 29 Dec 02:02:00.698 * The server is now ready to accept connections on port 6379 #-------------------------- #connect to redis-server apt-get install redis-tools redis-cli 127.0.0.1:6379> set name debugo OK 127.0.0.1:6379> set name leo OK 127.0.0.1:6379> quit ll /var/lib/redis/ drwxr-xr-x 2 999 root 4096 Dec 29 10:02 ./ drwxr-xr-x 41 root root 4096 Dec 29 09:37 ../ -rw-r--r-- 1 999 999 90 Dec 29 10:09 appendonly.aof docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4ff429636421 redis:2 "/entrypoint.sh redi 23 minutes ago Up 23 minutes 0.0.0.0:6379->6379/tcp redis-s01 #---------------------------------------- #5. starting mysqld #create data volume dir mkdir /var/lib/mysql #automatic initialization by dockerfile(See https://github.com/tutumcloud/tutum-docker-mysql) docker run -d -v /var/lib/mysql:/var/lib/mysql -p 3306:3306 -e MYSQL_PASS="debugo" tutum/mysql #connect to mysql-server docker logs 5b2000f24017ca89471ae01323e500bf4f72a9f391c0273d30fd066eeb043dc5 => An empty or uninitialized MySQL volume is detected in /var/lib/mysql => Installing MySQL ... root@docker01:/var/lib/redis# docker logs 5b2000f24017ca89471ae01323e500bf4f72a9f391c0273d30fd066eeb043dc5 => An empty or uninitialized MySQL volume is detected in /var/lib/mysql => Installing MySQL ... => Done! => Creating admin user ... => Waiting for confirmation of MySQL service startup, trying 0/13 ... root@docker01:/var/lib/redis# docker logs 5b2000f24017ca89471ae01323e500bf4f72a9f391c0273d30fd066eeb043dc5 => An empty or uninitialized MySQL volume is detected in /var/lib/mysql => Installing MySQL ... => Done! => Creating admin user ... => Waiting for confirmation of MySQL service startup, trying 0/13 ... => Creating MySQL user admin with preset password => Done! ======================================================================== You can now connect to this MySQL Server using: mysql -uadmin -pdebugo -h<host> -P<port> Please remember to change the above password as soon as possible! MySQL user 'root' has no password but only allows local connections ======================================================================== #后台进程 docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5b2000f24017 tutum/mysql:5.6 "/run.sh" 2 minutes ago Up 2 minutes 0.0.0.0:3306->3306/tcp romantic_mestorf ...... pstree init-+-acpid ...... |-docker-+-2*[docker---4*[{docker}]] | |-mysqld_safe---mysqld---21*[{mysqld}] | |-redis-server---2*[{redis-server}] | `-12*[{docker}] |
参考:
官网Use Cases
官网Docs
Docker中文社区
在Docker容器之间拷贝数据:原理与操作示例
《Docker —— 从入门到实践》
还有人要包养D。。。。