[root@docker-lnmp mysql]# docker images //列出本地镜像
REPOSITORY TAG IMAGE ID CREATED SIZE
centos mysql-5.6 9f7abd48947c 8 minutes ago 5.23GB
centos nginx-php 49937451198f 2 hours ago 1.5GB
centos 7 8652b9f0cb4c 9 months ago 204MB
[root@docker-lnmp mysql]# docker run -dit -p 3306:3306 --device-write-bps /dev/sda:10M 9f7abd48947c /bin/bash //限制Mysql容器写 /dev/sda 的速率为 10 MB/s
471b16b80432ed07fc5cc58a52626e3ff8b526b41f2c6ef020c48b7525abb3b1
[root@docker-lnmp mysql]# docker ps //列出当前运行容器
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
471b16b80432 9f7abd48947c "/bin/bash"7 seconds ago Up 7 seconds 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp strange_ride
f0e9ae37d111 49937451198f "/bin/bash"59 minutes ago Up 59 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp, 9000/tcp adoring_chaplygin
[root@docker-lnmp mysql]# docker exec -it 471b16b80432 /bin/bash //进入容器[root@471b16b80432 mysql-5.6.29]# /etc/init.d/mysqld start //启动mysql
Starting MySQL............ SUCCESS!
9.进入数据库授权
[root@471b16b80432 mysql-5.6.29]# mysql -uroot -p123456
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.6.29 Source distribution
Copyright (c)2000, 2016, 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> create database wordpress default charset utf8 COLLATE utf8_general_ci; //创建库
Query OK, 1 row affected (0.00 sec)
mysql> grant all privileges on wordpress.* to 'wordpress'@'%' identified by '123456' with grant option; //提权
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>exit
Bye
测试
三、备份
1.将所有容器快照
[root@docker-lnmp nginx]# docker images //列出当前镜像
REPOSITORY TAG IMAGE ID CREATED SIZE
centos mysql-5.6 9f7abd48947c 2 hours ago 5.23GB
centos nginx-php 49937451198f 4 hours ago 1.5GB
centos 7 8652b9f0cb4c 9 months ago 204MB
[root@docker-lnmp nginx]# docker ps //列出当前容器
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
471b16b80432 9f7abd48947c "/bin/bash" 2 hours ago Up 45 minutes 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp strange_ride
f0e9ae37d111 49937451198f "/bin/bash" 3 hours ago Up 44 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp, 9000/tcp adoring_chaplygin
[root@docker-lnmp nginx]# docker export 471b16b80432 > test.tar //快照
[root@docker-lnmp nginx]# docker export f0e9ae37d111 > test1.tar
[root@docker-lnmp nginx]# cat test1.tar | docker import - centos:new //导入
sha256:294ec6eeecf7033e5aeaebf74af10dfc674a9e46036dda22fc4f26d60af8bf5c
[root@docker-lnmp nginx]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos new 294ec6eeecf7 5 seconds ago 1.12GB
centos latest e21f68845c4e 4 minutes ago 3.93GB
centos mysql-5.6 9f7abd48947c 2 hours ago 5.23GB
centos nginx-php 49937451198f 4 hours ago 1.5GB
centos 7 8652b9f0cb4c 9 months ago 204MB
[root@docker-lnmp nginx]#
2.将镜像保存成tar包
[root@docker-lnmp ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos new 294ec6eeecf7 4 minutes ago 1.12GB
centos latest e21f68845c4e 8 minutes ago 3.93GB
centos mysql-5.6 9f7abd48947c 2 hours ago 5.23GB
centos nginx-php 49937451198f 4 hours ago 1.5GB
centos 7 8652b9f0cb4c 9 months ago 204MB
[root@docker-lnmp ~]# docker save -o mysql.tar centos:mysql-5.6 //镜像打包[root@docker-lnmp ~]# docker save -o nginx-php.tar centos:nginx-php[root@docker-lnmp ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
471b16b80432 9f7abd48947c "/bin/bash"2 hours ago Up About an hour 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp strange_ride
f0e9ae37d111 49937451198f "/bin/bash"3 hours ago Up About an hour 0.0.0.0:80->80/tcp, :::80->80/tcp, 9000/tcp adoring_chaplygin
[root@docker-lnmp ~]# docker stop f0e9ae37d111 //停止容器
f0e9ae37d111
[root@docker-lnmp ~]# docker rm f0e9ae37d111 //删除容器
f0e9ae37d111
[root@docker-lnmp ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
471b16b80432 9f7abd48947c "/bin/bash"2 hours ago Up About an hour 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp strange_ride
[root@docker-lnmp ~]# docker rmi 49937451198f //删除镜像
Untagged: centos:nginx-php
Deleted: sha256:49937451198f4a55b6b87aebc0fef871f8b8bfc3b8896c36898a2d657b7151a7
Deleted: sha256:798beb69684dcc0e68ea2da81f840abe5071269921da5323ab3066254de05cae
Deleted: sha256:1e1a390be892101a130bcacb69f9ea5b3baced89ef6c25bd285090ed10f2df71
Deleted: sha256:d47fd147128ce948ebaa92ad5e1b7d34fbd292e4c020dcd5402625c491394ea1
Deleted: sha256:c95e0953ee20aa4fba29836600036d75d537d6bfc141edf776693e185fbefd1d
Deleted: sha256:3ca74aab4cfdb808c33252da6f785385187e9519a1dc0d591e7da997e0fd1e0c
Deleted: sha256:f0ea9bb50c77f53010de59dcb9175e56be9a63e526b8af0aa43fdbefc3df9408
Deleted: sha256:48b267dfde5da157154234169e3b46b76f600ae8341277ccabd0a8f97c059528
Deleted: sha256:544c76a2a560449e1c6dcc55d4fbcbea83fa199cc163a25d905d4b0e233c71cc
Deleted: sha256:ae4a6f8426d1ecdb5701f2abb0f439bbecb7e240e975e1435d648e4e3ac2ea98
Deleted: sha256:9a73005ed0401547c197cc2ac1b04f3955f64f9d51773c3f6f23f701f6de8d26
Deleted: sha256:1f247e97b6408e0b13ae0a2cfd695c536f66b1185830b48507b55fcdae798370
Deleted: sha256:84cd37ec1affe70bdb4aae22f51e7e4b48bfd14f4f799a5a80d9db5493916437
Deleted: sha256:28f89e253a336575c99df2e102a7770a34261427d5640f95447eb231610916b5
Deleted: sha256:8e4a5927ff8357e3e2a516083823e20569a83199d55e1be31220a1a343574349
Deleted: sha256:d5595b052df4b399f659280d2e94c7c55c926b09f02c9f41436234a07b0d16f2
Deleted: sha256:2c18ebcc39f46f92e38c064ecf845fb3403497ddabd7cfc95a26d4ac3685a62a
Deleted: sha256:6316a4b40982a50e082efbdca3de15ae2119b28e02975921038ca8f3a66cc353
Deleted: sha256:03d4b4757a2cfe5712a186e38e68e63bd9082e3fa7182ad9972c3841484b3923
Deleted: sha256:0aac80401195082232b14788f15c1e94f8349df729dc9f276a00a15704266d11
Deleted: sha256:52f720b089128529f70b44483f501988fd5612e8678234e0f908b9809ab781a0
Deleted: sha256:89244a06f844354cd8bfda268911e72f0cada7cebecfe8ecb276d606b9cae1cd
Deleted: sha256:3bd4f1a60c5f36646bc970c51f8a0c9c7dc358b2395e5d88753b9d10f1179b7f
Deleted: sha256:e08548779292218b1bd39f02a7c1a600c275a84edb7593e4f369b949884ee1e1
Deleted: sha256:08797ee2d117ba0fd78d7b0336048e1856c2665e431f6b8995212d85d7436690
Deleted: sha256:1ae0ff23af45211c9bddfa7983778b7540d3e25377a9874544928bca898b39d6
Deleted: sha256:8262b1c25d180d23cef3d2363a7943761f585662d811ee5cd6270602d4315e15
Deleted: sha256:f1d2400b8bf814f6934b70b330e605eb92577ed664e01d3c0ef5bedf93c7aaf2
Deleted: sha256:c7374622eb462a9f7316a70f78fc59832535b9f95dc85c88b5cbab8e852fa20f
Deleted: sha256:549aa9b7c1bfb51ccdaa8ac2c7369fbc0f1a6435326cb3ea5d84fb109a575821
Deleted: sha256:d5edab69a51a60c221a890e0b8e8ef96cc438b8f145c9cc059c76aa9ef07c77e
Deleted: sha256:3f5f37171d38522a21edf3f5cf4b1a5d8bd12fec6d8aa1979f7f683f3b7d89d6
Deleted: sha256:d3f19941df2e08fbbcc54f7dbd05e0f8e77a91ec47164fb979cd6ab25a1d2017
Deleted: sha256:3dffe8ed4c7f3e32e77ace738f8ffbfb220ba2502229547e7dc6cae0409749c1
Deleted: sha256:4d175d855a41333458027f97e9bb90679c7ed494f5cd300d8c99ce231f1724c7
Deleted: sha256:e29a6dbf9ae501b7ff938a8da7cbfde85cf1eeb726c9b67411a9666a381715c1
Deleted: sha256:836a6adf7d95ae01eb8218d2d5d64ade82f5d2c935ad9128df96a2bcbbfa1ac0
Deleted: sha256:476602113db6ab77e6bbe86e0732b55ae2f11a4310f8bc0a272efc4710eac1e3
Deleted: sha256:6205fe26be270e1337ca88c4a173f89e89fc89ef7c46ec19414eba7a86825439
Deleted: sha256:d0757fbf0b7ab397901660ef32a24902b37e1df0aed7e4212ebe25e51cc930cd
Deleted: sha256:aee8e21b08f148547dff3172e5d59eb51298ebe2e0d0ce89c4a395e5f801dc89
Deleted: sha256:0420579f2da4d52aa9305f1b3be6c03367fafa6f94af23c463669e38231c06f5
Deleted: sha256:dcae663015338133e85e4df4ca50d8a7c02297da7f8b9e7518b7d2b616734126
Deleted: sha256:d2b397a9601e55575ddc2d3b05aa575cf41069492d62b8fb640b9c32e89e9bfc
Deleted: sha256:01113d337b2441529ec44f04ffdd8fd43a4867ae550a18c31885b49b1865fcef
Deleted: sha256:f42a93d770df014cb6fc6a1b62a2d7ca33cfb473a97ee96f7bf66509ea05efb5
Deleted: sha256:22ca3ca34a6e64eaddc7b2752774a533dd874af8fea0eb02130c345eecfccba8
Deleted: sha256:35ec1a1572b32269db94d3eada70b264e7d70bfff1c8cb8de232189cfa5d4844
Deleted: sha256:d1343865775c37013a79669d76a4c1f9c389595e60c88b86a46bf8784bc355de
Deleted: sha256:3ccd2b0c58292e4da156edf125b70e77daa5d8bc6d7b92e6a40b6b344a4e36c9
Deleted: sha256:6703dfd556ff9e3456269bf20ed762eeeeeb2449fc875b3ed55920743080204a
Deleted: sha256:f673938e8d4dc39dcf0479c0e746a9867e7a1c57604f1f256918272b782b97b3
Deleted: sha256:0ccd4c4d77c46310f0142824240125a06b72d8b2513c9dc52bb48815c5c7b174
Deleted: sha256:9c0ac58930250a6bc42ba840ab9dec1a40a55b08a047bd9a9ef24a27837344b6
Deleted: sha256:a5740803388d1ab2361ef6602e454da543f96ca658400f09c07c6a28f6c33e1a
Deleted: sha256:0a17232f20671952388946ad2a6cf23253a63f16cf4e2f0a490757ec7b0bf021
[root@docker-lnmp docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos new 294ec6eeecf7 24 minutes ago 1.12GB
centos latest e21f68845c4e 28 minutes ago 3.93GB
centos mysql-5.6 9f7abd48947c 2 hours ago 5.23GB
centos 7 8652b9f0cb4c 9 months ago 204MB
[root@docker-lnmp docker]# [root@docker-lnmp ~]# docker load < nginx-php.tar //恢复镜像
0b403d97ab8a: Loading layer [==================================================>]241.9MB/241.9MB
f231d1996a4b: Loading layer [==================================================>]272.6MB/272.6MB
89cdbbe04d33: Loading layer [==================================================>]379.4kB/379.4kB
846f154783c2: Loading layer [==================================================>]6.12MB/6.12MB
dd21710970bd: Loading layer [==================================================>]87.55kB/87.55kB
329690c7f111: Loading layer [==================================================>]26.74MB/26.74MB
0a5ba8b1b594: Loading layer [==================================================>]3.072kB/3.072kB
ba7258957556: Loading layer [==================================================>]5.12kB/5.12kB
7f201305f815: Loading layer [==================================================>]6.656kB/6.656kB
abc924abe9e0: Loading layer [==================================================>]29.44MB/29.44MB
352ef5be6541: Loading layer [==================================================>]7.168kB/7.168kB
ced5b710d18c: Loading layer [==================================================>]244.3MB/244.3MB
05045c051718: Loading layer [==================================================>]2.288MB/2.288MB
f61fdd726223: Loading layer [==================================================>]4.28MB/4.28MB
4db34a4bb9bd: Loading layer [==================================================>]113.9MB/113.9MB
d5232d646e05: Loading layer [==================================================>]380.2MB/380.2MB
cbc8332e3121: Loading layer [==================================================>]71.68kB/71.68kB
399481a9f170: Loading layer [==================================================>]5.632kB/5.632kB
c74bd30961e3: Loading layer [==================================================>]12.8kB/12.8kB
7b5772e508e6: Loading layer [==================================================>]26.62kB/26.62kB
b4bfdccd94bd: Loading layer [==================================================>]26.62kB/26.62kB
0c16eb7a654d: Loading layer [==================================================>]26.62kB/26.62kB
8c75d0d3c725: Loading layer [==================================================>]26.62kB/26.62kB
765d12e5a98f: Loading layer [==================================================>]26.62kB/26.62kB
0a2565a87311: Loading layer [==================================================>]26.62kB/26.62kB
a9c721ae6aa7: Loading layer [==================================================>]26.62kB/26.62kB
9ea89679305d: Loading layer [==================================================>]26.62kB/26.62kB
Loaded image: centos:nginx-php
[root@docker-lnmp ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
471b16b80432 9f7abd48947c "/bin/bash"2 hours ago Up About an hour 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp strange_ride
[root@docker-lnmp ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos new 294ec6eeecf7 18 minutes ago 1.12GB
centos latest e21f68845c4e 23 minutes ago 3.93GB
centos mysql-5.6 9f7abd48947c 2 hours ago 5.23GB
centos nginx-php 49937451198f 4 hours ago 1.5GB
centos 7 8652b9f0cb4c 9 months ago 204MB
[root@docker-lnmp ~]#