centos8启动docker-mysql8容器
生活随笔
收集整理的這篇文章主要介紹了
centos8启动docker-mysql8容器
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
【README】
本文記錄了 centos8 安裝,啟動mysql8的docker容器的步驟;
【1】安裝mysql8 docker容器
步驟1, 查看mysql8 docker鏡像版本 ;
最簡單的方式是上? Docker Hubhttps://hub.docker.com/直接搜索mysql,查看其 tag,如下:
?? 步驟2,下載 mysql:8.0.26 版本鏡像;
# 查看本地所有鏡像 [root@centos204 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE tomcat latest 4ce9babdd885 2 days ago 680MB hello-world latest feb5d9fea6a5 3 weeks ago 13.3kB# 下載 mysql 8.0.26 鏡像 [root@centos204 ~]# docker pull mysql:8.0.26 8.0.26: Pulling from library/mysql b380bbd43752: Pull complete f23cbf2ecc5d: Pull complete 30cfc6c29c0a: Pull complete b38609286cbe: Pull complete 8211d9e66cd6: Pull complete 2313f9eeca4a: Pull complete 7eb487d00da0: Pull complete a5d2b117a938: Pull complete 1f6cb474cd1c: Pull complete 896b3fd2ab07: Pull complete 532e67ebb376: Pull complete 233c7958b33f: Pull complete Digest: sha256:5d52dc010398db422949f079c76e98f6b62230e5b59c0bf7582409d2c85abacb Status: Downloaded newer image for mysql:8.0.26 docker.io/library/mysql:8.0.26# 查看本地所有鏡像 [root@centos204 ~]# [root@centos204 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE tomcat latest 4ce9babdd885 2 days ago 680MB mysql 8.0.26 9da615fced53 2 days ago 514MB hello-world latest feb5d9fea6a5 3 weeks ago 13.3kB [root@centos204 ~]#步驟3,啟動mysql容器
# 啟動mysql容器 [root@centos204 ~]# docker run -d --name mysql01 mysql:8.0.26 9c44ea82b1507e6bce54b69a786066ae56cb95c36411efa1cee4695e6c39525f# 查看容器列表 ,exited 表示啟動失敗;或未啟動 [root@centos204 ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9c44ea82b150 mysql:8.0.26 "docker-entrypoint.s…" 12 seconds ago Exited (1) 4 seconds ago mysql01 99e3813639c8 tomcat "catalina.sh run" 11 hours ago Exited (255) 2 minutes ago 0.0.0.0:8886->8080/tcp, :::8886->8080/tcp naughty_maxwell e7f01a261ee8 tomcat "catalina.sh run" 11 hours ago Exited (255) 2 minutes ago 0.0.0.0:8887->8080/tcp, :::8887->8080/tcp beautiful_proskuriakova 0b1be1a3dcd2 tomcat "catalina.sh run" 11 hours ago Exited (255) 2 minutes ago 0.0.0.0:8888->8080/tcp, :::8888->8080/tcp modest_heyrovsky 0a5b713c0021 hello-world "/hello" 35 hours ago Exited (0) 35 hours ago frosty_turing# 查看mysql容器日志 [root@centos204 ~]# docker logs 9c44ea82b150 2021-10-16 01:33:47+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.26-1debian10 started. 2021-10-16 01:33:51+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql' 2021-10-16 01:33:51+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.26-1debian10 started. # 報錯原因 2021-10-16 01:33:51+00:00 [ERROR] [Entrypoint]: Database is uninitialized and password option is not specifiedYou need to specify one of the following:- MYSQL_ROOT_PASSWORD- MYSQL_ALLOW_EMPTY_PASSWORD- MYSQL_RANDOM_ROOT_PASSWORD [root@centos204 ~]#步驟4,指定mysql密碼為 root,賬號默認為root;
# 重新啟動mysql docker容器,設置端口映射,密碼 [root@centos204 ~]# docker run --name mysql01 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -d mysql:8.0.26 720f23458abfdfafa93707e83f1cbb2ff085eb47d68c91d43088b0da7db97923# 查看所有docker容器 [root@centos204 ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 720f23458abf mysql:8.0.26 "docker-entrypoint.s…" 49 seconds ago Up 45 seconds 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp mysql01 99e3813639c8 tomcat "catalina.sh run" 11 hours ago Exited (255) 17 minutes ago 0.0.0.0:8886->8080/tcp, :::8886->8080/tcp naughty_maxwell e7f01a261ee8 tomcat "catalina.sh run" 11 hours ago Exited (255) 17 minutes ago 0.0.0.0:8887->8080/tcp, :::8887->8080/tcp beautiful_proskuriakova 0b1be1a3dcd2 tomcat "catalina.sh run" 12 hours ago Exited (255) 17 minutes ago 0.0.0.0:8888->8080/tcp, :::8888->8080/tcp modest_heyrovsky 0a5b713c0021 hello-world "/hello" 35 hours ago Exited (0) 35 hours ago frosty_turing [root@centos204 ~]#步驟5,開放3306防火墻訪問端口
# 開放3306防火墻訪問端口 [root@centos204 ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent success [root@centos204 ~]# firewall-cmd --reload success [root@centos204 ~]# firewall-cmd --zone=public --list-ports 8888/tcp 8887/tcp 8886/tcp 3306/tcp步驟6, 通過dbeaver連接 192.168.163.204:3306
【2】 啟動多個mysql-docker容器
步驟1,開啟2個mysql-docker容器,端口為3302 3303;
并設置mysql服務器參數, 參考了 https://hub.docker.com/_/mysql?tab=description
[root@centos204 ~]# docker run --name mysql02 -p 3302:3306 -e MYSQL_ROOT_PASSWORD=root -d mysql:8.0.26 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci 3d4caede6869e33e6cd1d267ed80cbc4f89faab8288b64c4b17d5ef40005e91d [root@centos204 ~]# docker run --name mysql03 -p 3303:3306 -e MYSQL_ROOT_PASSWORD=root -d mysql:8.0.26 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci 13132c9e47f35aeaf9e6cc9567a72f9d41850ad42deeb294c4a98ef2e9094034# 查看所有mysql-docker容器 [root@centos204 ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 13132c9e47f3 mysql:8.0.26 "docker-entrypoint.s…" 2 minutes ago Up About a minute 33060/tcp, 0.0.0.0:3303->3306/tcp, :::3303->3306/tcp mysql03 3d4caede6869 mysql:8.0.26 "docker-entrypoint.s…" 3 minutes ago Up 3 minutes 33060/tcp, 0.0.0.0:3302->3306/tcp, :::3302->3306/tcp mysql02 720f23458abf mysql:8.0.26 "docker-entrypoint.s…" 39 minutes ago Up 39 minutes 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp mysql01步驟2, 開通3302 3303 防火墻網絡權限 ;
# 開通3302 3303 端口 [root@centos204 ~]# firewall-cmd --zone=public --add-port=3302/tcp --permanent success [root@centos204 ~]# firewall-cmd --zone=public --add-port=3303/tcp --permanent success[root@centos204 ~]# firewall-cmd --reload success [root@centos204 ~]# firewall-cmd --zone=public --list-ports 8888/tcp 8887/tcp 8886/tcp 3306/tcp 3302/tcp 3303/tcp [root@centos204 ~]#步驟3, win10的dbeaver 測試結果;
【補充】
更多mysql-docker容器啟動參數,refer2 Docker Hub
總結
以上是生活随笔為你收集整理的centos8启动docker-mysql8容器的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: centos8上docker tomca
- 下一篇: mysql 表字段信息从一张表迁移到另一