CentOS container installation in Docker uses MySQL

CentOS image in Docker uses MySQL

##1 Environment & Demand

#1.1 surroundings###

Mac
Docker
 - CentOS 6.9-MySQL 5.7

#1.2 demand###

#2 docker's configuration##

#2.1 Pull CentOS mirror###

docker pull  centos:6.9

Check out the CentOS 6.9 image just pulled

docker images

#2.1 Create CentOS 6.9 Container###

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

#2.2 Enter/exit the container###

  1. Enter the container
# 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 /]#

  1. Exit the container

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 /]#

#3 Use MySQL in CentOS Container

3.1 Install MySQL

  1. Install wget
yum install -y wget
  1. Install MySQL official Yum Repository
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
  1. Install MySQL5.7
yum install -y mysql-server
  1. Start MySQL
service mysqld start
or
/etc/init.d/mysqld start
  1. change Password

https://blog.csdn.net/Coxhuang/article/details/103332961

  1. Enter MySQL
mysql -u root -p

#4 Save the current mirror##

  1. Exit the container
exit
  1. Submit container
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

CentOS container installation in Docker uses MySQL
Install MySql with Docker in CentOS7
Docker installation (CentOS7 installation)
CentOS7 docker installation
Install MySQL5.7 in centos7
Mysql8.0.15 installation configuration (centos7)
Docker CentOS installation method
Centos7 docker installation details
CentOS 6.x installation mysql5.7 record
CentOS environment installation of Docker
Docker EE installation on centos7
Container study notes CentOS7 install Docker
Install Centos7 operating system in Docker
The latest Centos7 installation Mysql8 guide
Centos7 mysql database installation and configuration
[Switch] CentOS7 64-bit installation mysql tutorial
2019-07-09 CentOS7 installation
centos7_1708 installation
Installation and use of Mysql under CentOS
MySQL 8.0 installation, deployment and configuration under CentOS 6/7
Deploy Docker and configure Nginx in CentOS
Detailed tutorial on installing MySQL 8 in CentOS 7
Novice learning Linux (eight) ---- MySql installation (Centos7)
Install Docker CE in yum under CentOS 7
Centos5 installation guide
Installation and configuration of JDK in CentOS 7 system
The most complete centos installation tutorial in history
CentOS7.2 install Mysql5.7.13
CentOS7 install MySQL
CentOS 7 install Docker
CentOS7 install Docker
Python - centos6 installation
CentOS install mysql
Centos7 install Docker
CentOS7 install mysql
CentOS 7 install MySQL 5.6
Centos7 install docker18
centos7 install docker
Installation and configuration of CentOS 7 in VMware Workstation
CentOS8 install MySQL8.0
CentOS7 install mysql8
MySQL 8.0 installation and deployment under CentOS, super detailed!
CentOS7 install MySQL8
CentOS 6 install Docker
Centos8 install Docker
Centos MySQL8 configuration
centos 7.5 install mysql5.7.17
MySQL 8.0 installation, deployment and configuration tutorial on CentOS 8
Installation and simple practice of MySQL in ubuntu environment (1)
Detailed installation steps of CentOS6.4 system in virtual machine
CentOS online installation RabbitMQ3.7
Install Docker on Centos7
Zabbix 2.2.20 installation details (Centos6.9)
Install php in centos
CentOS 7 install Docker service
Install mysql5.7 under CentOS7
Centos source installation Python3
lamp (centos7) installation lamp environment
CentOS 7.2 Yum install MySQL 5.6
Centos7 install Mysql8 tutorial
Centos7 mqtt cluster installation