Docker安裝、配置Tomcat叢集、Mysql主從
阿新 • • 發佈:2019-02-08
獲取映象:[[email protected] ~]# docker pull centos:7Trying to pull repository docker.io/library/centos ... 7: Pulling from docker.io/library/centos3d8673bd162a: Pull complete Digest: sha256:a66ffcb73930584413de83311ca11a4cb4938c9b2521d331026dad970c19adf4Status: Downloaded newer image for docker.io/centos:7[[email protected] ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEdocker.io/centos 7 970633036444 2 weeks ago 196.7 MBdocker.io/debian 7 dc81f1af026c 2 weeks ago 84.9 MBdocker.io/centos 6.6 2c886f766286 6 weeks ago 202.6 MB---------------------------------------------------------------------------------------------------- docker pull <映象名:tag> #從官網拉取映象 docker search <映象名> #搜尋線上可用映象名 -----------------------------------------------------------------------------------------------------刪除映象:[[email protected] ~]# docker rmi 2c886f766286Untagged: docker.io/centos:6.6Deleted: sha256:2c886f766286449b76ad90a7ce577b988e48fe5a3ed9a75c53fb81f783946831Deleted: sha256:c1acbd321a478f30cea685bddad3d1d44e70e5054e855b86ed1354fb95f64698[ [email protected] ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEdocker.io/centos 7 970633036444 2 weeks ago 196.7 MBdocker.io/debian 7 dc81f1af026c 2 weeks ago 84.9 MB驗證下載的映象是否正確:[[email protected] ~]# docker run -i -t debian /bin/bashUnable to find image 'debian:latest' locallyTrying to pull repository docker.io/library/debian ... latest: Pulling from docker.io/library/debian357ea8c3d80b: Pull complete Digest: sha256:ffb60fdbc401b2a692eef8d04616fca15905dce259d1499d96521970ed0bec36Status: Downloaded newer image for docker.io/debian:latest[email protected]c9754d098c8f:/# [[email protected] ~]# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESc9754d098c8f debian "/bin/bash" 29 seconds ago Up 27 seconds gloomy_liskov[[email protected] ~]# docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESc9754d098c8f debian "/bin/bash" 2 minutes ago Up 2 minutes gloomy_liskov[email protected]:/# exit //如果映象退出exit[[email protected] ~]# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES[[email protected] ~]# docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESc9754d098c8f debian "/bin/bash" 4 minutes ago Exited (0) About a minute ago gloomy_liskov---------------------------------------------------------------------------------------------------docker top <container> #顯示容器內執行的程序 docker images #查詢所有的映象,預設是最近建立的排在最上。 docker ps #檢視正在執行的容器 docker ps -l #檢視最後退出的容器的ID docker ps -a #檢視所有的容器,包括退出的。docker logs {容器ID|容器名稱} #查詢某個容器的所有操作記錄。 docker logs -f {容器ID|容器名稱} #實時檢視容易的操作記錄。 ---------------------------------------------------------------------------------------//刪除正在執行的容器[[email protected] ~]# docker rm $(docker ps -a -q)5ee5f7a43c08ef38c124fc8c7ab0bf5a2e3878d21bf30c41682579ac4d613cd0a71f5ca8c9754d098c8fda1c585c416cbebe5e0d6c446c7bd146682b[[email protected] ~]# docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES-------------------------------------------------------------------------------------------------------docker rm$(docker ps -a -q) #刪除所有容器 docker rm <容器名or ID> #刪除單個容器 docker rmi <ID> #刪除單個映象 docker rmi$(docker images | grep none | awk '{print $3}' | sort -r) ------------------------------------------------------------------------------------------//複製一個映象[[email protected] mydockerbuild]# docker tag bb1a16c6f475 maryatdocker/docker-whale:latest[[email protected] mydockerbuild]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEdocker-whale latest bb1a16c6f475 2 minutes ago 256.2 MBmaryatdocker/docker-whale latest bb1a16c6f475 2 minutes ago 256.2 MBdocker.io/hello-world latest c54a2cc56cbb 6 weeks ago 1.848 kBdocker.io/docker/whalesay latest 6b362a9f73eb 14 months ago 247 MB建立映象:[[email protected] ~]# docker run -i -t centos:6.6 /bin/bash[[email protected] /]# touch test[[email protected] /]# lsbin dev etc home lib lib64 lost+found media mnt opt proc root run sbin selinux srv sys testtmp usr var[[email protected] /]# exitexit[[email protected] ~]# docker commit -m "added a new file" -a "Docker cxp"docker: "commit" requires a minimum of 1 argument.See '/usr/bin/docker-current commit --help'.Usage: docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]Create a new image from a container's changes[[email protected] ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEdocker.io/centos 7 970633036444 2 weeks ago 196.7 MBdocker.io/debian 7 dc81f1af026c 2 weeks ago 84.9 MBdocker.io/debian latest 1b01529cc499 2 weeks ago 125.1 MBdocker.io/centos 6.6 2c886f766286 6 weeks ago 202.6 MB----------------------------------------------------------------------------------------引數: -a, --author=””作者資訊 -m,--message=””提交資訊 -p,--pause=true提交時暫停容器執行----------------------------------------------------------------------------------------建立映象:[[email protected] ~]# docker create debian:7[[email protected] ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEdocker.io/debian 7 dc81f1af026c 2 weeks ago 84.9 MB進入容器:匯出容器:[[email protected] ~]# docker export 31556cc3c436 > /opt/debian.tar[[email protected] ~]# ls /opt/debian.tar /opt/debian.tar安裝:[[email protected] ~]# yum install net-tools檢視本系統IP地址:安裝倉庫:[[email protected] ~]# docker pull registryUsing default tag: latestTrying to pull repository docker.io/library/registry ... latest: Pulling from docker.io/library/registrye110a4a17941: Pull complete 2ee5ed28ffa7: Pull complete d1562c23a8aa: Pull complete 06ba8e23299f: Pull complete 802d2a9c64e8: Pull complete Digest: sha256:1b68f0d54837c356e353efb04472bc0c9a60ae1c8178c9ce076b01d2930bcc5dStatus: Downloaded newer image for docker.io/registry:latest[[email protected] ~]# docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registry registryc3972270fc5d2f68cb7beeee7ddbde2471b37055f18d934c9473be278f0a325b[[email protected] ~]# docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESc3972270fc5d registry "/entrypoint.sh /etc/" 15 seconds ago Up 13 seconds 0.0.0.0:5000->5000/tcp tender_bartik使用伺服器的ip地址 測試一下我們自己的私有倉庫好不好用 執行curl--------------------------------------------------------------------------------------------------------docker搭建tomcat叢集:[[email protected] ~]# docker run -it -p 48080:8080 -v /root/software/:/mnt/software/ --name tomcat1 2c88 /bin/bash[[email protected] ~]# docker run -it -p 58080:8080 -v /root/software/:/mnt/software/ --name tomcat2 2c88 /bin/bash
[[email protected] ~]# docker pull hub.c.163.com/nce2/mysql:5.6Trying to pull repository hub.c.163.com/nce2/mysql ... 5.6: Pulling from hub.c.163.com/nce2/mysqlf4ab0b34ba6a: Pull complete ec98cd60600f: Pull complete a3ed95caeb02: Pull complete 396e622170d4: Pull complete 65d62a084566: Pull complete 6bbdcff5fa60: Pull complete edc2e7792fdc: Pull complete fda4a67523f7: Pull complete 64392f90df87: Pull complete 3f1300a78a30: Pull complete a34550f73a87: Pull complete c42721b9b9d7: Pull complete f4c4bad7c45c: Pull complete c00368654739: Pull complete be24f7e4c4c8: Pull complete 832a2ceeea32: Pull complete Digest: sha256:1c0c33bc6f801b1f6ed03a180dc5ff31abbfff9d587ffe2bd40006b506b81536Status: Downloaded newer image for hub.c.163.com/nce2/mysql:5.6建立mysql5.6容器 1master+3個slave[[email protected] ~]# docker run --name mysql-master -d -P hub.c.163.com/nce2/mysql:5.653d9dd333004e725a0bffffbaa531a473875fffb519813250f860220c0794b77[[email protected] ~]# docker run --name mysql-slave1 -d -P hub.c.163.com/nce2/mysql:5.6946ea0bf25af0373e331c64c024e302bbb570f46dc114f7881b65001bbef7302[[email protected] ~]# docker run --name mysql-slave2 -d -P hub.c.163.com/nce2/mysql:5.6c36247b619acc2269ed07abeebcd287992bfc73f889fca7a4d976a38e896f478[[email protected] ~]# docker run --name mysql-slave3 -d -P hub.c.163.com/nce2/mysql:5.647f57e8dccc7a8093270949a5be805fc20e49a5707a26867bcb107510e5b23b9[[email protected] ~]# 通過主機命令列進入master容器[[email protected] ~]# docker exec -it mysql-master bash[email protected]:/# 在master中建立一個數據庫test_docker[email protected]:/# mysql -uroot -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 3Server version: 5.6.19-v1-log MySQL Community Server (GPL)Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || #bak_database || mysql || performance_schema || test |+--------------------+5 rows in set (0.00 sec)mysql> create database test_docker;Query OK, 1 row affected (0.00 sec)mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || #bak_database || mysql || performance_schema || test || test_docker |+--------------------+6 rows in set (0.00 sec)mysql> quit[email protected]:/# cd /etc/[email protected]:/etc/apt# echo deb http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse >> sources.list[email protected]:/etc/apt# echo deb http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse >> sources.list[email protected]:/etc/apt# echo deb http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse >> sources.list[email protected]:/etc/apt# echo deb http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse >> sources.list[email protected]:/etc/apt# echo deb http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse >> sources.list[email protected]:/etc/apt# echo deb-src http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse >> sources.list[email protected]:/etc/apt# echo deb-src http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse >> sources.list[email protected]:/etc/apt# echo deb-src http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse >> sources.list[email protected]:/etc/apt# echo deb-src http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse >> sources.list[email protected]:/etc/apt# echo deb-src http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse >> sources.list [email protected]:/etc/apt# apt-get updateIgn http://mirrors.163.com trusty InReleaseGet:1 http://mirrors.163.com trusty-updates InRelease [65.9 kB]Get:2 http://mirrors.163.com trusty-security InRelease [65.9 kB]Get:3 http://mirrors.163.com trusty-proposed InRelease [65.9 kB]Get:4 http://mirrors.163.com trusty-backports InRelease [65.9 kB]Get:5 http://mirrors.163.com trusty Release.gpg [933 B]Get:6 http://mirrors.163.com trusty Release [58.5 kB] Get:7 http://mirrors.163.com trusty-updates/main Sources [380 kB]Get:8 http://mirrors.163.com trusty-updates/restricted Sources [5360 B] Get:9 http://mirrors.163.com trusty-updates/universe Sources [163 kB] Get:10 http://mirrors.163.com trusty-updates/multiverse Sources [7137 B] Get:11 http://mirrors.163.com trusty-updates/main amd64 Packages [889 kB] Get:12 http://mirrors.163.com trusty-updates/universe amd64 Packages [373 kB] Get:13 http://mirrors.163.com trusty-updates/restricted amd64 Packages [15.9 kB]Get:14 http://mirrors.163.com trusty-updates/multiverse amd64 Packages [14.8 kB]Get:15 http://mirrors.163.com trusty-security/main Sources [119 kB] Get:16 http://mirrors.163.com trusty-security/restricted Sources [4064 B] Get:17 http://mirrors.163.com trusty-security/universe Sources [41.5 kB] Get:18 http://mirrors.163.com trusty-security/multiverse Sources [2760 B] Get:19 http://mirrors.163.com trusty-security/main amd64 Packages [523 kB] Get:20 http://mirrors.163.com trusty-security/restricted amd64 Packages [13.0 kB]Get:21 http://mirrors.163.com trusty-security/universe amd64 Packages [136 kB] Get:22 http://mirrors.163.com trusty-security/multiverse amd64 Packages [4990 B]Get:23 http://mirrors.163.com trusty-proposed/main Sources [121 kB] Get:24 http://mirrors.163.com trusty-proposed/restricted Sources [28 B] Get:25 http://mirrors.163.com trusty-proposed/universe Sources [17.9 kB] Get:26 http://mirrors.163.com trusty-proposed/multiverse Sources [28 B] Get:27 http://mirrors.163.com trusty-proposed/main amd64 Packages [114 kB] Get:28 http://mirrors.163.com trusty-proposed/restricted amd64 Packages [28 B] Get:29 http://mirrors.163.com trusty-proposed/universe amd64 Packages [17.7 kB]Get:30 http://mirrors.163.com trusty-proposed/multiverse amd64 Packages [28 B] Get:31 http://mirrors.163.com trusty-backports/main Sources [9592 B] Get:32 http://mirrors.163.com trusty-backports/restricted Sources [28 B] Get:33 http://mirrors.163.com trusty-backports/universe Sources [35.2 kB] Get:34 http://mirrors.163.com trusty-backports/multiverse Sources [1898 B] Get:35 http://mirrors.163.com trusty-backports/main amd64 Packages [13.3 kB] Get:36 http://mirrors.163.com trusty-backports/restricted amd64 Packages [28 B]Get:37 http://mirrors.163.com trusty-backports/universe amd64 Packages [43.2 kB]Get:38 http://mirrors.163.com trusty-backports/multiverse amd64 Packages [1571 B]Get:39 http://mirrors.163.com trusty/main Sources [1064 kB] Get:40 http://mirrors.163.com trusty/restricted Sources [5433 B] Get:41 http://mirrors.163.com trusty/universe Sources [6399 kB] Get:42 http://mirrors.163.com trusty/multiverse Sources [174 kB] Get:43 http://mirrors.163.com trusty/main amd64 Packages [1350 kB] Get:44 http://mirrors.163.com trusty/universe amd64 Packages [5859 kB] Get:45 http://mirrors.163.com trusty/restricted amd64 Packages [13.0 kB] Get:46 http://mirrors.163.com trusty/multiverse amd64 Packages [132 kB] Fetched 18.4 MB in 26s (688 kB/s) Reading package lists... DoneW: Duplicate sources.list entry http://mirrors.163.com/ubuntu/ trusty/main amd64 Packages (/var/lib/apt/lists/mirrors.163.com_ubuntu_dists_trusty_main_binary-amd64_Packages)W: Duplicate sources.list entry http://mirrors.163.com/ubuntu/ trusty/universe amd64 Packages (/var/lib/apt/lists/mirrors.163.com_ubuntu_dists_trusty_universe_binary-amd64_Packages)W: Duplicate sources.list entry http://mirrors.163.com/ubuntu/ trusty-updates/main amd64 Packages (/var/lib/apt/lists/mirrors.163.com_ubuntu_dists_trusty-updates_main_binary-amd64_Packages)W: Duplicate sources.list entry http://mirrors.163.com/ubuntu/ trusty-updates/universe amd64 Packages (/var/lib/apt/lists/mirrors.163.com_ubuntu_dists_trusty-updates_universe_binary-amd64_Packages)W: You may want to run apt-get update to correct these problems[email protected]:/etc/apt# apt-get install vimReading package lists... DoneBuilding dependency tree Reading state information... DoneThe following extra packages will be installed: libgpm2 libpython2.7 vim-common vim-runtimeSuggested packages: gpm ctags vim-doc vim-scriptsThe following NEW packages will be installed: libgpm2 libpython2.7 vim vim-common vim-runtime0 upgraded, 5 newly installed, 0 to remove and 52 not upgraded.Need to get 6994 kB of archives.After this operation, 32.0 MB of additional disk space will be used.Do you want to continue? [Y/n] yGet:1 http://mirrors.163.com/ubuntu/ trusty/main libgpm2 amd64 1.20.4-6.1 [16.5 kB]Get:2 http://mirrors.163.com/ubuntu/ trusty-updates/main libpython2.7 amd64 2.7.6-8ubuntu0.2 [1039 kB]Get:3 http://mirrors.163.com/ubuntu/ trusty/main vim-common amd64 2:7.4.052-1ubuntu3 [95.6 kB]Get:4 http://mirrors.163.com/ubuntu/ trusty/main vim-runtime all 2:7.4.052-1ubuntu3 [4888 kB]Get:5 http://mirrors.163.com/ubuntu/ trusty/main vim amd64 2:7.4.052-1ubuntu3 [956 kB]Fetched 6994 kB in 8s (817 kB/s) debconf: delaying package configuration, since apt-utils is not installedSelecting previously unselected package libgpm2:amd64.(Reading database ... 13727 files and directories currently installed.)Preparing to unpack .../libgpm2_1.20.4-6.1_amd64.deb ...Unpacking libgpm2:amd64 (1.20.4-6.1) ...Selecting previously unselected package libpython2.7:amd64.Preparing to unpack .../libpython2.7_2.7.6-8ubuntu0.2_amd64.deb ...Unpacking libpython2.7:amd64 (2.7.6-8ubuntu0.2) ...Selecting previously unselected package vim-common.Preparing to unpack .../vim-common_2%3a7.4.052-1ubuntu3_amd64.deb ...Unpacking vim-common (2:7.4.052-1ubuntu3) ...Selecting previously unselected package vim-runtime.Preparing to unpack .../vim-runtime_2%3a7.4.052-1ubuntu3_all.deb ...Adding 'diversion of /usr/share/vim/vim74/doc/help.txt to /usr/share/vim/vim74/doc/help.txt.vim-tiny by vim-runtime'Adding 'diversion of /usr/share/vim/vim74/doc/tags to /usr/share/vim/vim74/doc/tags.vim-tiny by vim-runtime'Unpacking vim-runtime (2:7.4.052-1ubuntu3) ...Selecting previously unselected package vim.Preparing to unpack .../vim_2%3a7.4.052-1ubuntu3_amd64.deb ...Unpacking vim (2:7.4.052-1ubuntu3) ...Processing triggers for mime-support (3.54ubuntu1.1) ...Setting up libgpm2:amd64 (1.20.4-6.1) ...Setting up libpython2.7:amd64 (2.7.6-8ubuntu0.2) ...Setting up vim-common (2:7.4.052-1ubuntu3) ...Setting up vim-runtime (2:7.4.052-1ubuntu3) ...Processing /usr/share/vim/addons/docSetting up vim (2:7.4.052-1ubuntu3) ...update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vim (vim) in auto modeupdate-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vimdiff (vimdiff) in auto modeupdate-alternatives: using /usr/bin/vim.basic to provide /usr/bin/rvim (rvim) in auto modeupdate-alternatives: using /usr/bin/vim.basic to provide /usr/bin/rview (rview) in auto modeupdate-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vi (vi) in auto modeupdate-alternatives: using /usr/bin/vim.basic to provide /usr/bin/view (view) in auto modeupdate-alternatives: using /usr/bin/vim.basic to provide /usr/bin/ex (ex) in auto modeupdate-alternatives: using /usr/bin/vim.basic to provide /usr/bin/editor (editor) in auto modeProcessing triggers for libc-bin (2.19-0ubuntu6.6) ...W: Duplicate sources.list entry http://mirrors.163.com/ubuntu/ trusty/main amd64 Packages (/var/lib/apt/lists/mirrors.163.com_ubuntu_dists_trusty_main_binary-amd64_Packages)W: Duplicate sources.list entry http://mirrors.163.com/ubuntu/ trusty/universe amd64 Packages (/var/lib/apt/lists/mirrors.163.com_ubuntu_dists_trusty_universe_binary-amd64_Packages)W: Duplicate sources.list entry http://mirrors.163.com/ubuntu/ trusty-updates/main amd64 Packages (/var/lib/apt/lists/mirrors.163.com_ubuntu_dists_trusty-updates_main_binary-amd64_Packages)W: Duplicate sources.list entry http://mirrors.163.com/ubuntu/ trusty-updates/universe amd64 Packages (/var/lib/apt/lists/mirrors.163.com_ubuntu_dists_trusty-updates_universe_binary-amd64_Packages)W: You may want to run apt-get update to correct these problems[email protected]:/etc/apt# apt-get update Ign http://mirrors.163.com trusty InReleaseHit http://mirrors.163.com trusty-updates InReleaseHit http://mirrors.163.com trusty-security InReleaseHit http://mirrors.163.com trusty-proposed InReleaseHit http://mirrors.163.com trusty-backports InReleaseHit http://mirrors.163.com trusty Release.gpg Hit http://mirrors.163.com trusty Release Hit http://mirrors.163.com trusty-updates/main SourcesHit http://mirrors.163.com trusty-updates/restricted SourcesHit http://mirrors.163.com trusty-updates/universe SourcesHit http://mirrors.163.com trusty-updates/multiverse SourcesHit http://mirrors.163.com trusty-updates/main amd64 PackagesHit http://mirrors.163.com trusty-updates/universe amd64 PackagesHit http://mirrors.163.com trusty-updates/restricted amd64 PackagesHit http://mirrors.163.com trusty-updates/multiverse amd64 PackagesHit http://mirrors.163.com trusty-security/main SourcesHit http://mirrors.163.com trusty-security/restricted Sources Hit http://mirrors.163.com trusty-security/universe Sources Hit http://mirrors.163.com trusty-security/multiverse Sources Hit http://mirrors.163.com trusty-security/main amd64 Packages Hit http://mirrors.163.com trusty-security/restricted amd64 Packages Hit http://mirrors.163.com trusty-security/universe amd64 Packages Hit http://mirrors.163.com trusty-security/multiverse amd64 Packages Hit http://mirrors.163.com trusty-proposed/main SourcesHit http://mirrors.163.com trusty-proposed/restricted SourcesHit http://mirrors.163.com trusty-proposed/universe SourcesHit http://mirrors.163.com trusty-proposed/multiverse Sources Hit http://mirrors.163.com trusty-proposed/main amd64 PackagesHit http://mirrors.163.com trusty-proposed/restricted amd64 Packages Hit http://mirrors.163.com trusty-proposed/universe amd64 PackagesHit http://mirrors.163.com trusty-proposed/multiverse amd64 Packages Hit http://mirrors.163.com trusty-backports/main SourcesHit http://mirrors.163.com trusty-backports/restricted SourcesHit http://mirrors.163.com trusty-backports/universe SourcesHit http://mirrors.163.com trusty-backports/multiverse SourcesHit http://mirrors.163.com trusty-backports/main amd64 PackagesHit http://mirrors.163.com trusty-backports/restricted amd64 PackagesHit http://mirrors.163.com trusty-backports/universe amd64 PackagesHit http://mirrors.163.com trusty-backports/multiverse amd64 PackagesHit http://mirrors.163.com trusty/main SourcesHit http://mirrors.163.com trusty/restricted SourcesHit http://mirrors.163.com trusty/universe SourcesHit http://mirrors.163.com trusty/multiverse SourcesHit http://mirrors.163.com trusty/main amd64 PackagesHit http://mirrors.163.com trusty/universe amd64 PackagesHit http://mirrors.163.com trusty/restricted amd64 PackagesHit http://mirrors.163.com trusty/multiverse amd64 PackagesReading package lists... Done W: Duplicate sources.list entry http://mirrors.163.com/ubuntu/ trusty/main amd64 Packages (/var/lib/apt/lists/mirrors.163.com_ubuntu_dists_trusty_main_binary-amd64_Packages)W: Duplicate sources.list entry http://mirrors.163.com/ubuntu/ trusty/universe amd64 Packages (/var/lib/apt/lists/mirrors.163.com_ubuntu_dists_trusty_universe_binary-amd64_Packages)W: Duplicate sources.list entry http://mirrors.163.com/ubuntu/ trusty-updates/main amd64 Packages (/var/lib/apt/lists/mirrors.163.com_ubuntu_dists_trusty-updates_main_binary-amd64_Packages)W: Duplicate sources.list entry http://mirrors.163.com/ubuntu/ trusty-updates/universe amd64 Packages (/var/lib/apt/lists/mirrors.163.com_ubuntu_dists_trusty-updates_universe_binary-amd64_Packages)W: You may want to run apt-get update to correct these problems[email protected]:/etc/apt# apt-get install net-toolsReading package lists... DoneBuilding dependency tree Reading state information... DoneThe following NEW packages will be installed: net-tools0 upgraded, 1 newly installed, 0 to remove and 52 not upgraded.Need to get 175 kB of archives.After this operation, 725 kB of additional disk space will be used.Get:1 http://mirrors.163.com/ubuntu/ trusty-updates/main net-tools amd64 1.60-25ubuntu2.1 [175 kB]Fetched 175 kB in 0s (570 kB/s)debconf: delaying package configuration, since apt-utils is not installedSelecting previously unselected package net-tools.(Reading database ... 15414 files and directories currently installed.)Preparing to unpack .../net-tools_1.60-
----------------------------------------------------------------------------------------------------------------------------------
[[email protected] ~]# docker pull hub.c.163.com/nce2/mysql:5.6Trying to pull repository hub.c.163.com/nce2/mysql ... 5.6: Pulling from hub.c.163.com/nce2/mysqlf4ab0b34ba6a: Pull complete ec98cd60600f: Pull complete a3ed95caeb02: Pull complete 396e622170d4: Pull complete 65d62a084566: Pull complete 6bbdcff5fa60: Pull complete edc2e7792fdc: Pull complete fda4a67523f7: Pull complete 64392f90df87: Pull complete 3f1300a78a30: Pull complete a34550f73a87: Pull complete c42721b9b9d7: Pull complete f4c4bad7c45c: Pull complete c00368654739: Pull complete be24f7e4c4c8: Pull complete 832a2ceeea32: Pull complete Digest: sha256:1c0c33bc6f801b1f6ed03a180dc5ff31abbfff9d587ffe2bd40006b506b81536Status: Downloaded newer image for hub.c.163.com/nce2/mysql:5.6建立mysql5.6容器 1master+3個slave[[email protected] ~]# docker run --name mysql-master -d -P hub.c.163.com/nce2/mysql:5.653d9dd333004e725a0bffffbaa531a473875fffb519813250f860220c0794b77[[email protected] ~]# docker run --name mysql-slave1 -d -P hub.c.163.com/nce2/mysql:5.6946ea0bf25af0373e331c64c024e302bbb570f46dc114f7881b65001bbef7302[[email protected] ~]# docker run --name mysql-slave2 -d -P hub.c.163.com/nce2/mysql:5.6c36247b619acc2269ed07abeebcd287992bfc73f889fca7a4d976a38e896f478[[email protected] ~]# docker run --name mysql-slave3 -d -P hub.c.163.com/nce2/mysql:5.647f57e8dccc7a8093270949a5be805fc20e49a5707a26867bcb107510e5b23b9[[email protected] ~]# 通過主機命令列進入master容器[[email protected] ~]# docker exec -it mysql-master bash[email protected]:/# 在master中建立一個數據庫test_docker[email protected]:/# mysql -uroot -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 3Server version: 5.6.19-v1-log MySQL Community Server (GPL)Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || #bak_database || mysql || performance_schema || test |+--------------------+5 rows in set (0.00 sec)mysql> create database test_docker;Query OK, 1 row affected (0.00 sec)mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || #bak_database || mysql || performance_schema || test || test_docker |+--------------------+6 rows in set (0.00 sec)mysql> quit[email protected]:/# cd /etc/[email protected]:/etc/apt# echo deb http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse >> sources.list[email protected]:/etc/apt# echo deb http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse >> sources.list[email protected]:/etc/apt# echo deb http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse >> sources.list[email protected]:/etc/apt# echo deb http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse >> sources.list[email protected]:/etc/apt# echo deb http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse >> sources.list[email protected]:/etc/apt# echo deb-src http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse >> sources.list[email protected]:/etc/apt# echo deb-src http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse >> sources.list[email protected]:/etc/apt# echo deb-src http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse >> sources.list[email protected]:/etc/apt# echo deb-src http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse >> sources.list[email protected]:/etc/apt# echo deb-src http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse >> sources.list [email protected]:/etc/apt# apt-get updateIgn http://mirrors.163.com trusty InReleaseGet:1 http://mirrors.163.com trusty-updates InRelease [65.9 kB]Get:2 http://mirrors.163.com trusty-security InRelease [65.9 kB]Get:3 http://mirrors.163.com trusty-proposed InRelease [65.9 kB]Get:4 http://mirrors.163.com trusty-backports InRelease [65.9 kB]Get:5 http://mirrors.163.com trusty Release.gpg [933 B]Get:6 http://mirrors.163.com trusty Release [58.5 kB] Get:7 http://mirrors.163.com trusty-updates/main Sources [380 kB]Get:8 http://mirrors.163.com trusty-updates/restricted Sources [5360 B] Get:9 http://mirrors.163.com trusty-updates/universe Sources [163 kB] Get:10 http://mirrors.163.com trusty-updates/multiverse Sources [7137 B] Get:11 http://mirrors.163.com trusty-updates/main amd64 Packages [889 kB] Get:12 http://mirrors.163.com trusty-updates/universe amd64 Packages [373 kB] Get:13 http://mirrors.163.com trusty-updates/restricted amd64 Packages [15.9 kB]Get:14 http://mirrors.163.com trusty-updates/multiverse amd64 Packages [14.8 kB]Get:15 http://mirrors.163.com trusty-security/main Sources [119 kB] Get:16 http://mirrors.163.com trusty-security/restricted Sources [4064 B] Get:17 http://mirrors.163.com trusty-security/universe Sources [41.5 kB] Get:18 http://mirrors.163.com trusty-security/multiverse Sources [2760 B] Get:19 http://mirrors.163.com trusty-security/main amd64 Packages [523 kB] Get:20 http://mirrors.163.com trusty-security/restricted amd64 Packages [13.0 kB]Get:21 http://mirrors.163.com trusty-security/universe amd64 Packages [136 kB] Get:22 http://mirrors.163.com trusty-security/multiverse amd64 Packages [4990 B]Get:23 http://mirrors.163.com trusty-proposed/main Sources [121 kB] Get:24 http://mirrors.163.com trusty-proposed/restricted Sources [28 B] Get:25 http://mirrors.163.com trusty-proposed/universe Sources [17.9 kB] Get:26 http://mirrors.163.com trusty-proposed/multiverse Sources [28 B] Get:27 http://mirrors.163.com trusty-proposed/main amd64 Packages [114 kB] Get:28 http://mirrors.163.com trusty-proposed/restricted amd64 Packages [28 B] Get:29 http://mirrors.163.com trusty-proposed/universe amd64 Packages [17.7 kB]Get:30 http://mirrors.163.com trusty-proposed/multiverse amd64 Packages [28 B] Get:31 http://mirrors.163.com trusty-backports/main Sources [9592 B] Get:32 http://mirrors.163.com trusty-backports/restricted Sources [28 B] Get:33 http://mirrors.163.com trusty-backports/universe Sources [35.2 kB] Get:34 http://mirrors.163.com trusty-backports/multiverse Sources [1898 B] Get:35 http://mirrors.163.com trusty-backports/main amd64 Packages [13.3 kB] Get:36 http://mirrors.163.com trusty-backports/restricted amd64 Packages [28 B]Get:37 http://mirrors.163.com trusty-backports/universe amd64 Packages [43.2 kB]Get:38 http://mirrors.163.com trusty-backports/multiverse amd64 Packages [1571 B]Get:39 http://mirrors.163.com trusty/main Sources [1064 kB] Get:40 http://mirrors.163.com trusty/restricted Sources [5433 B] Get:41 http://mirrors.163.com trusty/universe Sources [6399 kB] Get:42 http://mirrors.163.com trusty/multiverse Sources [174 kB] Get:43 http://mirrors.163.com trusty/main amd64 Packages [1350 kB] Get:44 http://mirrors.163.com trusty/universe amd64 Packages [5859 kB] Get:45 http://mirrors.163.com trusty/restricted amd64 Packages [13.0 kB] Get:46 http://mirrors.163.com trusty/multiverse amd64 Packages [132 kB] Fetched 18.4 MB in 26s (688 kB/s) Reading package lists... DoneW: Duplicate sources.list entry http://mirrors.163.com/ubuntu/ trusty/main amd64 Packages (/var/lib/apt/lists/mirrors.163.com_ubuntu_dists_trusty_main_binary-amd64_Packages)W: Duplicate sources.list entry http://mirrors.163.com/ubuntu/ trusty/universe amd64 Packages (/var/lib/apt/lists/mirrors.163.com_ubuntu_dists_trusty_universe_binary-amd64_Packages)W: Duplicate sources.list entry http://mirrors.163.com/ubuntu/ trusty-updates/main amd64 Packages (/var/lib/apt/lists/mirrors.163.com_ubuntu_dists_trusty-updates_main_binary-amd64_Packages)W: Duplicate sources.list entry http://mirrors.163.com/ubuntu/ trusty-updates/universe amd64 Packages (/var/lib/apt/lists/mirrors.163.com_ubuntu_dists_trusty-updates_universe_binary-amd64_Packages)W: You may want to run apt-get update to correct these problems[email protected]:/etc/apt# apt-get install vimReading package lists... DoneBuilding dependency tree Reading state information... DoneThe following extra packages will be installed: libgpm2 libpython2.7 vim-common vim-runtimeSuggested packages: gpm ctags vim-doc vim-scriptsThe following NEW packages will be installed: libgpm2 libpython2.7 vim vim-common vim-runtime0 upgraded, 5 newly installed, 0 to remove and 52 not upgraded.Need to get 6994 kB of archives.After this operation, 32.0 MB of additional disk space will be used.Do you want to continue? [Y/n] yGet:1 http://mirrors.163.com/ubuntu/ trusty/main libgpm2 amd64 1.20.4-6.1 [16.5 kB]Get:2 http://mirrors.163.com/ubuntu/ trusty-updates/main libpython2.7 amd64 2.7.6-8ubuntu0.2 [1039 kB]Get:3 http://mirrors.163.com/ubuntu/ trusty/main vim-common amd64 2:7.4.052-1ubuntu3 [95.6 kB]Get:4 http://mirrors.163.com/ubuntu/ trusty/main vim-runtime all 2:7.4.052-1ubuntu3 [4888 kB]Get:5 http://mirrors.163.com/ubuntu/ trusty/main vim amd64 2:7.4.052-1ubuntu3 [956 kB]Fetched 6994 kB in 8s (817 kB/s) debconf: delaying package configuration, since apt-utils is not installedSelecting previously unselected package libgpm2:amd64.(Reading database ... 13727 files and directories currently installed.)Preparing to unpack .../libgpm2_1.20.4-6.1_amd64.deb ...Unpacking libgpm2:amd64 (1.20.4-6.1) ...Selecting previously unselected package libpython2.7:amd64.Preparing to unpack .../libpython2.7_2.7.6-8ubuntu0.2_amd64.deb ...Unpacking libpython2.7:amd64 (2.7.6-8ubuntu0.2) ...Selecting previously unselected package vim-common.Preparing to unpack .../vim-common_2%3a7.4.052-1ubuntu3_amd64.deb ...Unpacking vim-common (2:7.4.052-1ubuntu3) ...Selecting previously unselected package vim-runtime.Preparing to unpack .../vim-runtime_2%3a7.4.052-1ubuntu3_all.deb ...Adding 'diversion of /usr/share/vim/vim74/doc/help.txt to /usr/share/vim/vim74/doc/help.txt.vim-tiny by vim-runtime'Adding 'diversion of /usr/share/vim/vim74/doc/tags to /usr/share/vim/vim74/doc/tags.vim-tiny by vim-runtime'Unpacking vim-runtime (2:7.4.052-1ubuntu3) ...Selecting previously unselected package vim.Preparing to unpack .../vim_2%3a7.4.052-1ubuntu3_amd64.deb ...Unpacking vim (2:7.4.052-1ubuntu3) ...Processing triggers for mime-support (3.54ubuntu1.1) ...Setting up libgpm2:amd64 (1.20.4-6.1) ...Setting up libpython2.7:amd64 (2.7.6-8ubuntu0.2) ...Setting up vim-common (2:7.4.052-1ubuntu3) ...Setting up vim-runtime (2:7.4.052-1ubuntu3) ...Processing /usr/share/vim/addons/docSetting up vim (2:7.4.052-1ubuntu3) ...update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vim (vim) in auto modeupdate-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vimdiff (vimdiff) in auto modeupdate-alternatives: using /usr/bin/vim.basic to provide /usr/bin/rvim (rvim) in auto modeupdate-alternatives: using /usr/bin/vim.basic to provide /usr/bin/rview (rview) in auto modeupdate-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vi (vi) in auto modeupdate-alternatives: using /usr/bin/vim.basic to provide /usr/bin/view (view) in auto modeupdate-alternatives: using /usr/bin/vim.basic to provide /usr/bin/ex (ex) in auto modeupdate-alternatives: using /usr/bin/vim.basic to provide /usr/bin/editor (editor) in auto modeProcessing triggers for libc-bin (2.19-0ubuntu6.6) ...W: Duplicate sources.list entry http://mirrors.163.com/ubuntu/ trusty/main amd64 Packages (/var/lib/apt/lists/mirrors.163.com_ubuntu_dists_trusty_main_binary-amd64_Packages)W: Duplicate sources.list entry http://mirrors.163.com/ubuntu/ trusty/universe amd64 Packages (/var/lib/apt/lists/mirrors.163.com_ubuntu_dists_trusty_universe_binary-amd64_Packages)W: Duplicate sources.list entry http://mirrors.163.com/ubuntu/ trusty-updates/main amd64 Packages (/var/lib/apt/lists/mirrors.163.com_ubuntu_dists_trusty-updates_main_binary-amd64_Packages)W: Duplicate sources.list entry http://mirrors.163.com/ubuntu/ trusty-updates/universe amd64 Packages (/var/lib/apt/lists/mirrors.163.com_ubuntu_dists_trusty-updates_universe_binary-amd64_Packages)W: You may want to run apt-get update to correct these problems[email protected]:/etc/apt# apt-get update Ign http://mirrors.163.com trusty InReleaseHit http://mirrors.163.com trusty-updates InReleaseHit http://mirrors.163.com trusty-security InReleaseHit http://mirrors.163.com trusty-proposed InReleaseHit http://mirrors.163.com trusty-backports InReleaseHit http://mirrors.163.com trusty Release.gpg Hit http://mirrors.163.com trusty Release Hit http://mirrors.163.com trusty-updates/main SourcesHit http://mirrors.163.com trusty-updates/restricted SourcesHit http://mirrors.163.com trusty-updates/universe SourcesHit http://mirrors.163.com trusty-updates/multiverse SourcesHit http://mirrors.163.com trusty-updates/main amd64 PackagesHit http://mirrors.163.com trusty-updates/universe amd64 PackagesHit http://mirrors.163.com trusty-updates/restricted amd64 PackagesHit http://mirrors.163.com trusty-updates/multiverse amd64 PackagesHit http://mirrors.163.com trusty-security/main SourcesHit http://mirrors.163.com trusty-security/restricted Sources Hit http://mirrors.163.com trusty-security/universe Sources Hit http://mirrors.163.com trusty-security/multiverse Sources Hit http://mirrors.163.com trusty-security/main amd64 Packages Hit http://mirrors.163.com trusty-security/restricted amd64 Packages Hit http://mirrors.163.com trusty-security/universe amd64 Packages Hit http://mirrors.163.com trusty-security/multiverse amd64 Packages Hit http://mirrors.163.com trusty-proposed/main SourcesHit http://mirrors.163.com trusty-proposed/restricted SourcesHit http://mirrors.163.com trusty-proposed/universe SourcesHit http://mirrors.163.com trusty-proposed/multiverse Sources Hit http://mirrors.163.com trusty-proposed/main amd64 PackagesHit http://mirrors.163.com trusty-proposed/restricted amd64 Packages Hit http://mirrors.163.com trusty-proposed/universe amd64 PackagesHit http://mirrors.163.com trusty-proposed/multiverse amd64 Packages Hit http://mirrors.163.com trusty-backports/main SourcesHit http://mirrors.163.com trusty-backports/restricted SourcesHit http://mirrors.163.com trusty-backports/universe SourcesHit http://mirrors.163.com trusty-backports/multiverse SourcesHit http://mirrors.163.com trusty-backports/main amd64 PackagesHit http://mirrors.163.com trusty-backports/restricted amd64 PackagesHit http://mirrors.163.com trusty-backports/universe amd64 PackagesHit http://mirrors.163.com trusty-backports/multiverse amd64 PackagesHit http://mirrors.163.com trusty/main SourcesHit http://mirrors.163.com trusty/restricted SourcesHit http://mirrors.163.com trusty/universe SourcesHit http://mirrors.163.com trusty/multiverse SourcesHit http://mirrors.163.com trusty/main amd64 PackagesHit http://mirrors.163.com trusty/universe amd64 PackagesHit http://mirrors.163.com trusty/restricted amd64 PackagesHit http://mirrors.163.com trusty/multiverse amd64 PackagesReading package lists... Done W: Duplicate sources.list entry http://mirrors.163.com/ubuntu/ trusty/main amd64 Packages (/var/lib/apt/lists/mirrors.163.com_ubuntu_dists_trusty_main_binary-amd64_Packages)W: Duplicate sources.list entry http://mirrors.163.com/ubuntu/ trusty/universe amd64 Packages (/var/lib/apt/lists/mirrors.163.com_ubuntu_dists_trusty_universe_binary-amd64_Packages)W: Duplicate sources.list entry http://mirrors.163.com/ubuntu/ trusty-updates/main amd64 Packages (/var/lib/apt/lists/mirrors.163.com_ubuntu_dists_trusty-updates_main_binary-amd64_Packages)W: Duplicate sources.list entry http://mirrors.163.com/ubuntu/ trusty-updates/universe amd64 Packages (/var/lib/apt/lists/mirrors.163.com_ubuntu_dists_trusty-updates_universe_binary-amd64_Packages)W: You may want to run apt-get update to correct these problems[email protected]:/etc/apt# apt-get install net-toolsReading package lists... DoneBuilding dependency tree Reading state information... DoneThe following NEW packages will be installed: net-tools0 upgraded, 1 newly installed, 0 to remove and 52 not upgraded.Need to get 175 kB of archives.After this operation, 725 kB of additional disk space will be used.Get:1 http://mirrors.163.com/ubuntu/ trusty-updates/main net-tools amd64 1.60-25ubuntu2.1 [175 kB]Fetched 175 kB in 0s (570 kB/s)debconf: delaying package configuration, since apt-utils is not installedSelecting previously unselected package net-tools.(Reading database ... 15414 files and directories currently installed.)Preparing to unpack .../net-tools_1.60-