##1 Environment & Demand
Mac
Docker
- CentOS 6.9-MySQL 5.7
docker pull centos:6.9
Check out the CentOS 6.9 image just pulled
docker images
docker run -it centos:6.9/bin/bash
# Command comments are as follows:
# run:Command to create container(fixed format)
# - it:Run the container in interactive mode(general-i-t appears at the same time)
# /bin/bash:Enter commands using container commands(Enter the container terminal)
After entering the CentOS terminal, the content after the @ symbol in root@d2568b5fe7b3 refers to the ID corresponding to the container, and the container ID is not equal to the image ID
╭─[email protected] ~
╰─➤ docker ps 130 ↵
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d2568b5fe7b3 centos:6.9"/bin/bash"5 minutes ago Up 5 minutes happy_mcclintock
5437 aa4212f8 centos:6.8"/bin/bash" About an hour ago Up About an hour gifted_fermat
The first column of CONTAINER ID is the ID of the container, which is the string of content displayed after root@ after entering the container
STATUS is the status of the container, there are 7 types of container status
STATUS | Description |
---|---|
created | created |
restarting | restarting |
running | running |
removing | migrating |
paused | Pause |
exited | stop |
dead | Death |
# Enter the container
docker attach d2568b5fe7b3
# docker attach container ID
╭─[email protected] ~
╰─➤ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d2568b5fe7b3 centos:6.9"/bin/bash"33 minutes ago Up 33 minutes happy_mcclintock
5437 aa4212f8 centos:6.8"/bin/bash" About an hour ago Up About an hour gifted_fermat
╭─[email protected] ~
╰─➤ docker attach d2568b5fe7b3
[ root@d2568b5fe7b3 /]#
Exit and kill the container
╭─[email protected] ~
╰─➤ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5437 aa4212f8 centos:6.8"/bin/bash" About an hour ago Up About an hour gifted_fermat
╭─[email protected] ~
╰─➤ docker run -it centos:6.9/bin/bash
[ root@ced5ed59ec2c /]# ls
bin dev etc home lib lib64 lost+found media mnt opt proc root sbin selinux srv sys tmp usr var[root@ced5ed59ec2c /]# mkdir haha
[ root@ced5ed59ec2c /]# ls
bin dev etc haha home lib lib64 lost+found media mnt opt proc root sbin selinux srv sys tmp usr var[root@ced5ed59ec2c /]# exit
exit
╭─[email protected] ~
╰─➤ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5437 aa4212f8 centos:6.8"/bin/bash" About an hour ago Up About an hour gifted_fermat
╭─[email protected] ~
╰─➤ docker run -it centos:6.9/bin/bash
[ root@6e12db3af46f /]# ls
bin dev etc home lib lib64 lost+found media mnt opt proc root sbin selinux srv sys tmp usr var[root@6e12db3af46f /]#
After exiting, the background container is still running
[ root@6e12db3af46f /]# mkdir haha2
[ root@6e12db3af46f /]# ls
bin dev etc haha2 home lib lib64 lost+found media mnt opt proc root sbin selinux srv sys tmp usr var[root@6e12db3af46f /]# % ╭─[email protected] ~
╰─➤ docker attach 6e12db3af46f
[ root@6e12db3af46f /]# ls
bin dev etc haha2 home lib lib64 lost+found media mnt opt proc root sbin selinux srv sys tmp usr var[root@6e12db3af46f /]#
yum install -y wget
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql57-community-release-el7-10.noarch.rpm
yum install -y mysql-server
service mysqld start
or
/etc/init.d/mysqld start
https://blog.csdn.net/Coxhuang/article/details/103332961
mysql -u root -p
exit
docker commit 5437aa4212f8 centos:addmysql
# docker commit container ID image name:TAG
[ root@5437aa4212f8 /]# exit
exit
╭─[email protected] ~
╰─➤ docker commit 5437aa4212f8 centos:addmysql
sha256:25753ae423774c946936fd22ccb73d14967b0db87956b7fc0bed167e4049c572
╭─[email protected] ~
╰─➤ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos addmysql 25753ae42377 7 seconds ago 442MB
centos 6.8 82f3b5f3c58f 9 months ago 195MB
centos 6.9 2199b8eb8390 9 months ago 195MB
mysql 5.7.21 5195076672a7 22 months ago 371MB
╭─[email protected] ~
╰─➤ docker run -it centos:addmysql /bin/bash
[ root@cca8b56a08c2 /]# mysql -u root -p
Enter password:
ERROR 2002(HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)[root@cca8b56a08c2 /]# service mysqld start
Starting mysqld:[ OK ][root@cca8b56a08c2 /]#
Recommended Posts