前一段时间就在研究用Dockerfile构建MySQL镜像并实现容器启动过程中MySQL数据库系统的初始化,但被一些无关紧要的事儿给耽误了,经过查阅《dockerfile最佳实践》及MySQL数据库的迁移与备份还原的资料,整理了操作过程,并进行了实验,确认此方法可行:
MySQL数据库系统的初始化是指MySQL安装到OS上后所经历的initinstall过程,只有经过初始化的数据库系统才能提供数据存储服务、才能被应用程序使用。
实现MySQL在解压安装过程或容器启动过程中的数据库系统的初始化,有三个思路:
1、在CentOS环境中安装配置好MySQL,使MySQL处于可对外服务状态,并对此环境进行打包制作成虚拟化的镜像包;
2、在启动容器的过程中指定MySQL的环境变量,通过环境变量和初始化shell脚本完成MySQL数据库系统的初始化;
3、通过Dockerfile指定镜像的构建过程,并提前准备好MySQL数据库系统初始化所必须的meta数据和shell脚本,这相当于对数据库系统进行迁移还原。
本次实验采用的即是思路三。因为在实践过程中,思路一相当于为特定应用做的个性化定制,思路二在操作过程中总会遇到数据库连接失败的故障,稳定性较差。

本次实验操作的环境:
CentOS 7 1804,VMware 15 Pro,4GB内存、4核心CPU,宿主OS为Windows7SP1 64Bit。

操作系统环境准备
[googlebigtable@localhost ~]$ su - root
Password:
Last login: Tue May 19 02:28:07 EDT 2020 on pts/0
[root@localhost ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.original
[root@localhost ~]# ls -F /etc/yum.repos.d/
CentOS-Base.repo.original CentOS-CR.repo CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS-Media.repo CentOS-Sources.repo CentOS-Vault.repo
[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
--2020-05-19 03:00:48-- http://mirrors.163.com/.help/CentOS7-Base-163.repo
Resolving mirrors.163.com (mirrors.163.com)... 59.111.0.251
Connecting to mirrors.163.com (mirrors.163.com)|59.111.0.251|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1572 (1.5K) [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/CentOS-Base.repo’

100%[==========================================================================================================>] 1,572 --.-K/s in 0s

2020-05-19 03:00:48 (460 MB/s) - ‘/etc/yum.repos.d/CentOS-Base.repo’ saved [1572/1572]

[root@localhost ~]# ls -F /etc/yum.repos.d/
CentOS-Base.repo CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo
CentOS-Base.repo.original CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
[root@localhost ~]# cat -n /etc/yum.repos.d/CentOS-Base.repo
1 # CentOS-Base.repo
2 #
3 # The mirror system uses the connecting IP address of the client and the
4 # update status of each mirror to pick mirrors that are updated to and
5 # geographically close to the client. You should use this for CentOS updates
6 # unless you are manually picking other mirrors.
7 #
8 # If the mirrorlist= does not work for you, as a fall back you can try the
9 # remarked out baseurl= line instead.
10 #
11 #
12 [base]
13 name=CentOS-$releasever - Base - 163.com
14 #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
15 baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/
16 gpgcheck=1
17 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
18
19 #released updates
20 [updates]
21 name=CentOS-$releasever - Updates - 163.com
22 #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
23 baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/
24 gpgcheck=1
25 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
26
27 #additional packages that may be useful
28 [extras]
29 name=CentOS-$releasever - Extras - 163.com
30 #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
31 baseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch/
32 gpgcheck=1
33 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
34
35 #additional packages that extend functionality of existing packages
36 [centosplus]
37 name=CentOS-$releasever - Plus - 163.com
38 baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/
39 gpgcheck=1
40 enabled=0
41 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
[root@localhost ~]# yum clean all
Loaded plugins: fastestmirror, langpacks
Cleaning repos: base extras updates
Cleaning up everything
[root@localhost ~]# yum makecache
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/10): base/7/x86_64/group_gz | 153 kB 00:00:00
(2/10): base/7/x86_64/primary_db | 6.1 MB 00:00:04
.................................................................................................................................................
urw-fonts.noarch 0:2.4-16.el7

Complete!
[root@localhost ~]#
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.8.2003 (Core)
[root@localhost ~]# hostnamectl status
Static hostname: localhost.localdomain
Icon name: computer-vm
Chassis: vm
Machine ID: b1625b44a4c448b193b2318086920ba8
Boot ID: c5894807414c44f8b7878f2412d39436
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-862.el7.x86_64
Architecture: x86-64
[root@localhost ~]# rpm -q centos-release
centos-release-7-8.2003.0.el7.centos.x86_64
[root@localhost ~]# cat /proc/version
Linux version 3.10.0-862.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) ) #1 SMP Fri Apr 20 16:44:24 UTC 2018
[root@localhost ~]# uname -a
Linux localhost.localdomain 3.10.0-862.el7.x86_64 #1 SMP Fri Apr 20 16:44:24 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost ~]#
[root@localhost ~]# yum -y update
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
No packages marked for update
[root@localhost ~]#
[root@localhost ~]# ls -F
anaconda-ks.cfg initial-setup-ks.cfg
[root@localhost ~]# cd /home/googlebigtable/
[root@localhost googlebigtable]#ls -F
Desktop/ Documents/ Downloads/ Music/ Pictures/ Public/ Templates/ Videos/
[root@localhost googlebigtable]# mkdir -p temp/dockerworking
[root@localhost googlebigtable]# yum install -y tree
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
..................................................................................................................................................
Installed:
tree.x86_64 0:1.6.0-10.el7

Complete!
[root@localhost googlebigtable]# tree temp/
temp/
└── dockerworking

1 directory, 0 files
[root@localhost googlebigtable]#

用shell脚本安装Docker
[root@localhost dockerworking]# curl -sSL https://get.docker.com/ | sh

Executing docker install script, commit: 26ff363bcf3b3f5a00498ac43694bf1c7d9ce16c

  • sh -c 'yum install -y -q yum-utils'
    Package yum-utils-1.1.31-54.el7_8.noarch already installed and latest version
  • sh -c 'yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo'
    Loaded plugins: fastestmirror, langpacks
    adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
    grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
    repo saved to /etc/yum.repos.d/docker-ce.repo
  • '[' stable '!=' stable ']'
  • sh -c 'yum makecache'
    Loaded plugins: fastestmirror, langpacks
    Loading mirror speeds from cached hostfile
    base | 3.6 kB 00:00:00
    docker-ce-stable | 3.5 kB 00:00:00
    extras | 2.9 kB 00:00:00
    updates | 2.9 kB 00:00:00
    (1/4): docker-ce-stable/x86_64/updateinfo | 55 B 00:00:05
    (2/4): docker-ce-stable/x86_64/primary_db | 42 kB 00:00:01
    (3/4): docker-ce-stable/x86_64/other_db | 114 kB 00:00:01
    (4/4): docker-ce-stable/x86_64/filelists_db | 20 kB 00:00:16
    Metadata Cache Created
  • '[' -n '' ']'
  • sh -c 'yum install -y -q docker-ce'
    https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.13-3.2.el7.x86_64.rpm: [Errno 12] Timeout on https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.13-3.2.el7.x86_64.rpm: (28, 'Operation timed out after 30002 milliseconds with 0 out of 0 bytes received')
    Trying other mirror.
    https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-19.03.9-3.el7.x86_64.rpm: [Errno 12] Timeout on https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-19.03.9-3.el7.x86_64.rpm: (28, 'Operation timed out after 30001 milliseconds with 0 out of 0 bytes received')
    Trying other mirror.
    https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-cli-19.03.9-3.el7.x86_64.rpm: [Errno 12] Timeout on https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-cli-19.03.9-3.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
    Trying other mirror.
    https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.13-3.2.el7.x86_64.rpm: [Errno 12] Timeout on https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.13-3.2.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
    Trying other mirror.
    https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-19.03.9-3.el7.x86_64.rpm: [Errno 12] Timeout on https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-19.03.9-3.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
    Trying other mirror.
    https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-cli-19.03.9-3.el7.x86_64.rpm: [Errno 12] Timeout on https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-cli-19.03.9-3.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
    Trying other mirror.
    https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.13-3.2.el7.x86_64.rpm: [Errno 12] Timeout on https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.13-3.2.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
    Trying other mirror.
    https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-19.03.9-3.el7.x86_64.rpm: [Errno 12] Timeout on https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-19.03.9-3.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
    Trying other mirror.
    https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-cli-19.03.9-3.el7.x86_64.rpm: [Errno 12] Timeout on https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-cli-19.03.9-3.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
    Trying other mirror.
    warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/containerd.io-1.2.13-3.2.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY
    Public key for containerd.io-1.2.13-3.2.el7.x86_64.rpm is not installed
    Importing GPG key 0x621E9F35:
    Userid : "Docker Release (CE rpm) <docker@docker.com>"
    Fingerprint: 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
    From : https://download.docker.com/linux/centos/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!

WARNING: Adding a user to the "docker" group will grant the ability to run
containers which can be used to obtain root privileges on the
docker host.
Refer to https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface
for more information.
[root@localhost dockerworking]#
启动docker服务
[root@localhost dockerworking]# yum list installed | grep docker
containerd.io.x86_64 1.2.13-3.2.el7 @docker-ce-stable
docker-ce.x86_64 3:19.03.9-3.el7 @docker-ce-stable
docker-ce-cli.x86_64 1:19.03.9-3.el7 @docker-ce-stable
[root@localhost dockerworking]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@localhost dockerworking]# systemctl start docker
[root@localhost dockerworking]#
[root@localhost dockerworking]# ls -F /etc/ | grep docker
docker/
[root@localhost dockerworking]# ls -F /etc/docker/
key.json
[root@localhost dockerworking]# ttee /etc/docker/daemon.json <<-'EOF'

{
"registry-mirrors": ["https://alzgoonw.mirror.aliyuncs.com"]
}
EOF
{
"registry-mirrors": ["https://alzgoonw.mirror.aliyuncs.com"]
}
[root@localhost dockerworking]# cat -n /etc/docker/daemon.json
1 {
2 registry-mirrors": ["https://alzgoonw.mirror.aliyuncs.com"]
3 }
[root@localhost dockerworking]#
[root@localhost dockerworking]# systemctl daemon-reload
[root@localhost dockerworking]#systemctl restart docker
[root@localhost dockerworking]# service docker restart
Redirecting to /bin/systemctl restart docker.service
[root@localhost dockerworking]#
[root@localhost dockerworking]# ls -F
dockerubuntu/ gbtwithsshv0.tar
[root@localhost dockerworking]# cd dockerubuntu/
[root@localhost dockerubuntu]# vim Dockerfile
[root@localhost dockerubuntu]# vim setup.sh
[root@localhost dockerubuntu]# vim schema.sql
[root@localhost dockerubuntu]# vim privileges.sql
[root@localhost dockerubuntu]# ls -F
Dockerfile privileges.sql schema.sql setup.sh
[root@localhost dockerubuntu]# cat -n Dockerfile
1 FROM mysql:5.7.25
2 ENV MYSQL_ALLOW_EMPTY_PASSWORD yes
3 COPY setup.sh /mysql/setup.sh
4 COPY schema.sql /mysql/schema.sql
5 COPY privileges.sql /mysql/privileges.sql
6 CMD ["sh", "/mysql/setup.sh"]
[root@localhost dockerubuntu]# cat -n setup.sh
1 #!/bin/bash
2
3 set -e
4
5
6 echo '1. starting mysql...'
7
8 service mysql start
9
10
11 echo '2. creating database...'
12
13 mysql < /mysql/schema.sql
14
15 echo '3. setting password....'
16
17 mysql < /mysql/privileges.sql
18
19 echo service mysql status
20
21 echo '4. mysql for testformysqlinit is ready...'
22
23
24 tail -f /dev/null
[root@localhost dockerubuntu]# cat -n schema.sql
1 create database if not exists testformysqlinit;
[root@localhost dockerubuntu]# cat -n privileges.sql
1 use mysql;
2 set password for root@localhost = password('qwertyuiop2020');
3 grant all on . to root@'%' identified by 'qwertyuiop2020' with grant option;
4 flush privileges;
[root@localhost dockerubuntu]#
[root@localhost dockerubuntu]# docker build -t mysqlinit:mysql5725 .
Sending build context to Docker daemon 5.12kB
Step 1/6 : FROM mysql:5.7.25
5.7.25: Pulling from library/mysql
27833a3ba0a5: Pull complete
864c283b3c4b: Pull complete
cea281b2278b: Pull complete
8f856c14f5af: Pull complete
9c4f38c23b6f: Pull complete
1b810e1751b3: Pull complete
5479aaef3d30: Pull complete
1d924ec3d520: Pull complete
1ab7ae63ac60: Pull complete
08aa5f3680e9: Pull complete
a832d0a0972a: Pull complete
Digest: sha256:dba5fed182e64064b688ccd22b2f9cad4ee88608c82f8cff21e17bab8da72b81
Status: Downloaded newer image for mysql:5.7.25
---> 98455b9624a9
Step 2/6 : ENV MYSQL_ALLOW_EMPTY_PASSWORD yes
---> Running in 20c67e7a2821
Removing intermediate container 20c67e7a2821
---> 7b8f3e8b35e8
Step 3/6 : COPY setup.sh /mysql/setup.sh
---> 2eb86def7a40
Step 4/6 : COPY schema.sql /mysql/schema.sql
---> 212e9fbec90d
Step 5/6 : COPY privileges.sql /mysql/privileges.sql
---> 83160ca01bd7
Step 6/6 : CMD ["sh", "/mysql/setup.sh"]
---> Running in 67b4de01a0cf
Removing intermediate container 67b4de01a0cf
---> b43048b18ff1
Successfully built b43048b18ff1
Successfully tagged mysqlinit:mysql5725
[root@localhost dockerubuntu]#
[root@localhost dockerubuntu]# docker run --name mysqlinit -p 33060:3306 -d mysqlinit:mysql5725
5e0dfdfb6d034b8b62641b7fbf670e034cbb24486c456e63d8fbf952ec15e8e4
[root@localhost dockerubuntu]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysqlinit mysql5725 b43048b18ff1 21 minutes ago 372MB
<none> <none> fdbcd047e06b 3 hours ago 128MB
ubuntu1604 CMDtest fcdab87e5a82 4 hours ago 125MB
<none> <none> 8185bda8662c 4 hours ago 197MB
gbtwithssh v0 a371467d9077 24 hours ago 326MB
wordpress latest 675af3ca3193 4 days ago 540MB
ubuntu 16.04 005d2078bdfa 3 weeks ago 125MB
ubuntu 18.04 c3c304cb4f22 3 weeks ago 64.2MB
ubuntu 14.04 6e4f1fe62ff1 5 months ago 197MB
mysql 5.5 d404d78aa797 12 months ago 205MB
mysql 5.7.25 98455b9624a9 14 months ago 372MB
centos 7.5.1804 cf49811e3cdb 14 months ago 200MB
[root@localhost dockerubuntu]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5e0dfdfb6d03 mysqlinit:mysql5725 "docker-entrypoint.s…" 19 seconds ago Up 19 seconds 33060/tcp, 0.0.0.0:33060->3306/tcp mysqlinit
0d55d28e7556 6e4f1fe62ff1 "/bin/sh -c 'apt-get…" 39 minutes ago Exited (100) 31 minutes ago hungry_hoover
fe69ea4fceb2 cf49811e3cdb "/bin/sh -c 'yum -y …" 45 minutes ago Exited (1) 44 minutes ago nice_chaum
447f347b4807 fdbcd047e06b "/bin/sh -c 'apt-get…" 2 hours ago Exited (100) About an hour ago inspiring_diffie
d5aca6ac8f01 fdbcd047e06b "/bin/sh -c 'apt-get…" 3 hours ago Exited (100) 2 hours ago fervent_poincare
e103c446c82b fcdab87e5a82 "hostname" 4 hours ago Exited (0) 4 hours ago fervent_leakey
e2d84d1bc763 fcdab87e5a82 "hostnamectl status" 4 hours ago Created cool_bhabha
d93e878ffb47 fcdab87e5a82 "hostnamectl status" 4 hours ago Exited (1) 4 hours ago silly_moore
7d33e9e3a685 fcdab87e5a82 "/bin/date" 4 hours ago Exited (0) 4 hours ago clever_merkle
87db9e8e1ca0 fcdab87e5a82 "/bin/echo 'I'm excu…" 4 hours ago Exited (0) 4 hours ago stoic_benz
d64d6b812a74 8185bda8662c "/bin/echo this imag…" 4 hours ago Exited (0) 4 hours ago upbeat_sutherland
a3a6494e9354 8185bda8662c "/bin/echo hi,this i…" 4 hours ago Exited (0) 4 hours ago nifty_tereshkova
38cb9c00ee5f wordpress "docker-entrypoint.s…" 5 hours ago Up 5 hours 0.0.0.0:8080->80/tcp wordpress
c90e359d5af0 mysql:5.5 "docker-entrypoint.s…" 5 hours ago Up 5 hours 0.0.0.0:3306->3306/tcp mysql
8c6eb8f8d4ba cf49811e3cdb "/usr/sbin/init" 25 hours ago Exited (137) 16 hours ago ssh
b2dfd487a2f3 cf49811e3cdb "/usr/sbin/init" 25 hours ago Exited (137) 25 hours ago great_taussig
89e35ee3bc0e cf49811e3cdb "/bin/bash" 25 hours ago Exited (137) 25 hours ago centos7.5
[root@localhost dockerubuntu]#
[root@localhost dockerubuntu]# docker exec -it 5e0dfdfb6d03 /bin/bash
root@5e0dfdfb6d03:/# ls -F
bin/ dev/ entrypoint.sh@ home/ lib64/ mnt/ opt/ root/ sbin/ sys/ usr/
boot/ docker-entrypoint-initdb.d/ etc/ lib/ media/ mysql/ proc/ run/ srv/ tmp/ var/
root@5e0dfdfb6d03:/# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.25 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select user from user;
+---------------+
| user |
+---------------+
| root |
| mysql.session |
| mysql.sys |
| root |
+---------------+
4 rows in set (0.00 sec)

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| testformysqlinit |
+--------------------+
5 rows in set (0.00 sec)

mysql>select user,host from user;
+---------------+-----------+
| user | host |
+---------------+-----------+
| root | % |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+---------------+-----------+
4 rows in set (0.00 sec)

mysql> quit;br/>Bye
root@5e0dfdfb6d03:/#
root@5e0dfdfb6d03:/# exit
exit
[root@localhost dockerubuntu]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5e0dfdfb6d03 mysqlinit:mysql5725 "docker-entrypoint.s…" 9 minutes ago Up 9 minutes 33060/tcp, 0.0.0.0:33060->3306/tcp mysqlinit
0d55d28e7556 6e4f1fe62ff1 "/bin/sh -c 'apt-get…" 48 minutes ago Exited (100) 40 minutes ago hungry_hoover
fe69ea4fceb2 cf49811e3cdb "/bin/sh -c 'yum -y …" 54 minutes ago Exited (1) 53 minutes ago nice_chaum
447f347b4807 fdbcd047e06b "/bin/sh -c 'apt-get…" 2 hours ago Exited (100) About an hour ago inspiring_diffie
d5aca6ac8f01 fdbcd047e06b "/bin/sh -c 'apt-get…" 3 hours ago Exited (100) 2 hours ago fervent_poincare
e103c446c82b fcdab87e5a82 "hostname" 4 hours ago Exited (0) 4 hours ago fervent_leakey
e2d84d1bc763 fcdab87e5a82 "hostnamectl status" 4 hours ago Created cool_bhabha
d93e878ffb47 fcdab87e5a82 "hostnamectl status" 4 hours ago Exited (1) 4 hours ago silly_moore
7d33e9e3a685 fcdab87e5a82 "/bin/date" 4 hours ago Exited (0) 4 hours ago clever_merkle
87db9e8e1ca0 fcdab87e5a82 "/bin/echo 'I'm excu…" 4 hours ago Exited (0) 4 hours ago stoic_benz
d64d6b812a74 8185bda8662c "/bin/echo this imag…" 4 hours ago Exited (0) 4 hours ago upbeat_sutherland
a3a6494e9354 8185bda8662c "/bin/echo hi,this i…" 4 hours ago Exited (0) 4 hours ago nifty_tereshkova
38cb9c00ee5f wordpress "docker-entrypoint.s…" 5 hours ago Up 5 hours 0.0.0.0:8080->80/tcp wordpress
c90e359d5af0 mysql:5.5 "docker-entrypoint.s…" 5 hours ago Up 5 hours 0.0.0.0:3306->3306/tcp mysql
8c6eb8f8d4ba cf49811e3cdb "/usr/sbin/init" 25 hours ago Exited (137) 16 hours ago ssh
b2dfd487a2f3 cf49811e3cdb "/usr/sbin/init" 25 hours ago Exited (137) 25 hours ago great_taussig
89e35ee3bc0e cf49811e3cdb "/bin/bash" 25 hours ago Exited (137) 25 hours ago centos7.5
[root@localhost dockerubuntu]#
[root@localhost dockerubuntu]# docker commit -a "googlebigtable" -m "mysqlwithinit" 5e0dfdfb6d03 mysql5725init:v0
sha256:3587682e3a3c76167740f21b514fdd205aa9386adf693105355b87abccabe06d
[root@localhost dockerubuntu]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql5725init v0 3587682e3a3c 11 seconds ago 372MB
mysqlinit mysql5725 b43048b18ff1 35 minutes ago 372MB
<none> <none> fdbcd047e06b 3 hours ago 128MB
ubuntu1604 CMDtest fcdab87e5a82 4 hours ago 125MB
<none> <none> 8185bda8662c 4 hours ago 197MB
gbtwithssh v0 a371467d9077 25 hours ago 326MB
wordpress latest 675af3ca3193 4 days ago 540MB
ubuntu 16.04 005d2078bdfa 3 weeks ago 125MB
ubuntu 18.04 c3c304cb4f22 3 weeks ago 64.2MB
ubuntu 14.04 6e4f1fe62ff1 5 months ago 197MB
mysql 5.5 d404d78aa797 12 months ago 205MB
mysql 5.7.25 98455b9624a9 14 months ago 372MB
centos 7.5.1804 cf49811e3cdb 14 months ago 200MB
[root@localhost dockerubuntu]# docker save -o mysql5725initv0.tar mysql5725init:v0
[root@localhost dockerubuntu]# ls -F
Dockerfile mysql5725initv0.tar privileges.sql schema.sql setup.sh
[root@localhost dockerubuntu]#

至此,本次实验结束。

孟伯,20200411

交流联系:微信 1807479153 ,QQ 1807479153

用Dockerfile构建MySQL镜像并实现容器启动过程中MySQL数据库系统的初始化相关推荐

  1. spring中容器启动过程中初始化资源使用方法

    一.定义 在业务场景中,有时需要我们在容器启动过程中加载资源,完成数据的初始化或者配置,需要在调用前加载进spring容器过程中去,有以下一些方法来实现 1.定义静态常量,随着类的生命周期加载而提前加 ...

  2. 使用Dockerfile构建Docker镜像

    目录 前言 Dockerfile的书写规则及指令使用方法 创建Dockerfile,构建运行环境 构建镜像 Dockerfile参考示例 Dockerfile最佳实践 1. 前言 Dockfile是一 ...

  3. Dockerfile(Dockerfile的详细使用、通过Dockerfile构建apache镜像)

    文章目录 1 Dockerfile介绍 2 基本结构 2.1 Dockerfile分为四部分 3 Dockerfile 基础知识 4 Dockerfile常用指令 4.1 FROM 4.2 LABEL ...

  4. 通过Dockerfile构建Docker镜像

    Dockerfile是一个文本文件,其内包含了一条条的指令(Instruction),每一条指令构建一层,因此每一条指令的内容,就是描述该层应当如何构建. Dockerfile支持Shell类的行尾添 ...

  5. Docker使用Dockerfile构建简单镜像

    Docker使用Dockerfile构建简单镜像 首先确保系统已经安装docker 构建镜像 安装基础镜像 sudo docker pull ubuntu 查看镜像是否已经拉取成功 REPOSITOR ...

  6. Dockerfile构建Springboot镜像

    Dockerfile构建Springboot镜像 文章目录 Dockerfile构建Springboot镜像 简介 实例演示 前期准备 Docker环境 Springboot项目 Dockerfile ...

  7. 【DockerFile构建自定义镜像实操出现问题解决方案Failed to download metadata for repo ‘appstream‘: IPv4 forwarding disa】

    一.知识回顾 之前的内容都帮你整理好了,在这里哟! [0.Docker相关目录文章整理,可自行查看,包含多节内容] [1.Docker详细安装部署&阿里镜像地址配置] [2.Docker架构& ...

  8. 使用docker构建jenkins镜像并运行容器

    https://my.oschina.net/donhui/blog/470372?p={{currentPage+1}}   摘要: 使用docker构建jenkins镜像并运行容器 目录: 1.基 ...

  9. Dockerfile构建nginx镜像

    Dockerfile构建nginx镜像[root@bogon ~]# mkdir /opt/docker-file [root@bogon ~]# cd /opt/docker-file/ [root ...

最新文章

  1. Flex 3权威指南
  2. MaxCompute Mars开发指南
  3. 成都计算机安全学会怎么样,成都计算机专科大学
  4. H5+JS+相对单位rem实现第三方支付页(输入金额+模拟数字键盘+自适应布局+大写金额)
  5. Java性能分析点滴
  6. cygwin内子目录及其文件删除不掉,出现access deny错误
  7. TARS 微服务开源生态
  8. 移动端日期控件 mobiscroll
  9. Pattern Recognition and Machine Learning(模式识别与机器学习)第一章导读
  10. 网站安全检测:推荐8款免费的 Web 安全测试工具
  11. ​ClickHouse在手淘流量分析业务实践
  12. Magisk使用记录
  13. for(foo(‘a‘) ; foo(‘b‘) (i<2);foo(‘c‘))的执行结果
  14. 【PPT】2010/2013/2016实现在演示过程中拖拽图片/形状
  15. 2019年计算机二级考试mysql_2019年下半年计算机二级MySQL试题
  16. 7-158 判断4和7的倍数
  17. 第三部分 :简单句的补充(限定词/形容词/介词短语)
  18. MySQL数据库字符串(单行)函数#concat、length、tirm、replace、strcmp、substr等函数总结
  19. 题目:学生成绩管理系统设计(C语言程序设计期末作业)
  20. unity--google支付--billing4.0

热门文章

  1. html+css淘宝静态网页
  2. android 彩信发送,在部分手机上报错,提示activityNotFoundError。
  3. 前后端分离页面500错误,控制台不打印错误日志的错误定位
  4. Shell脚本切换root用户或获取root权限
  5. 【mssql】SQL Server2012编程入门经典(第四版)(上) 读书笔记
  6. matlab 椭圆参数传递,用MATLAB绘图已知椭圆参数方程
  7. c语言帮助记忆单词的小程序,帮助记忆单词的书课堂活动微信小程序软件_速记背单词...
  8. 在MDK 中忽略(suppress) 某一个警告
  9. 设计一个长方形类。成员变量包括:长度和宽度,成员函数除包括计算周长和计算面积外, 还包括用set方法来设置长方形的长度和宽度,以及用get的方法来获得长方形的长度和宽度 最后,编写一个测试程序来测试所
  10. linux怎么添加跃点数,Windows 7修改静态路由表的跃点数