接上节,v1.2之上又pip安装了一堆模块,镜像变的有点大了,现在的环境基础为linux+python3.7常用服务和机器学习模块:
进入之前做好的容器tag为v1.3:
docker run -t -i antony314/centos:v1.3 /bin/bash
下面开始安装mysql8.0,我是参考的这篇文章: CentOS7使用yum安装MySQL8.0
[root@3446a77085e1 tools]# cd /root/tools/
[root@3446a77085e1 tools]# wget https://repo.mysql.com/mysql80-community-release-el7-1.noarch.rpm
[root@3446a77085e1 tools]# yum localinstall mysql80-community-release-el7-1.noarch.rpm
[root@3446a77085e1 tools]# yum install mysql-community-server
然后准启动mysql server:
[root@3446a77085e1 tools]# service mysqld start
bash: service: command not found
command not found 于是安装下initscripts:
[root@3446a77085e1 tools]# yum list | grep initscripts
initscripts.x86_64 9.49.46-1.el7 base
[root@3446a77085e1 tools]# yum install initscripts -y
可以使用service了:
[root@3446a77085e1 tools]# whereis service
service: /usr/sbin/service
再尝试启动:
[root@3446a77085e1 tools]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
Failed to get D-Bus connection: Operation not permitted
看了下解决方案,应该是启动docker的时候需要增加--privileged 参数,先把当前的退出并保存镜像,然后再添加该参数run:
[root@3446a77085e1 tools]# exit
[root@小林のCentos 16:06:42 ~]>2$ docker commit -m="v1.4 not ready" -a="antony" 3446a77085e1 antony314/centos:v1.4_perpare
sha256:ab8b3ab25f88b7c4044bb80607d4562351d05ae30f96a6bda18fc40bcf7f803e
[root@小林のCentos 16:11:01 ~]>3$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
antony314/centos v1.4_perpare ab8b3ab25f88 5 seconds ago 3.63GB
antony314/centos v1.3 064b1178022a 3 days ago 1.66GB
antony314/centos v1.2-lite 423d4a8672c6 6 weeks ago 760MB
antony314/centos v1.2 c39870b10c73 7 weeks ago 760MB
antony314/centos v1.1 50b5b5058224 7 weeks ago 833MB
antony314/centos v1 47dd3157ad26 7 weeks ago 273MB
[root@小林のCentos 16:11:17 ~]>5$ docker run --privileged -t -i ab8b3ab25f88 /usr/sbin/init
但是:
然后又:
root@小林のCentos 17:09:25 ~]>2$ docker run -tdi --privileged ab8b3ab25f88 init
feb946fbc663c8aebb6a3d4d70894f0fba930e8c0a8dcc56d27992cf1c69beb4
查看ps找到使用init命令的容器id feb946fbc663:
然后 docker attch feb946fbc663 发现命令行会像差不多刚刚那样卡住,于是用exec可以再基于bash命令进入容器:
root@小林のCentos 17:09:25 ~]>2$ docker exec -it feb946fbc663 /bin/bash
[root@feb946fbc663 /]# service
Usage: service < option > | --status-all | [ service_name [ command | --full-restart ] ]
[root@feb946fbc663 /]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
参考时间发现好像最开始的时候第一次init进入容器的时候就成功启动了mysql:
这里留下一个疑问,过程中我是docker stop 过之前以为卡住的容器;N次。不应该是容器内启动mysql之后stop容器,mysql服务应该也不在了才对嘛?
第二天解决了以上疑问,正常情况容器退出进程也会退出,这才比较符合容器的含义。接下来继续,进入容器之后找mysql初始密码,然后设置下mysql:
[root@feb946fbc663 /]# grep 'temporary password' /var/log/mysqld.log
[root@feb946fbc663 /]# mysql -uroot -pos9.ReNe%M=+
mysql: [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 9
Server version: 8.0.15
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> ALTER USER 'root'@'localhost' IDENTIFIED BY 'XXXXXXXXXXXXX'
这里可能要注意下mysql8第一次进入reset密码时的坑: 简单参考这篇文章得到解决