[转]docker 部署 mysql + phpmyadmin 3种方法

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[转]docker 部署 mysql + phpmyadmin 3种方法相关的知识,希望对你有一定的参考价值。

本文转自:https://blog.csdn.net/Gekkoou/article/details/80897309

 

方法1: link

# 创建容器 test-mysql (千万别用 mysql:latest, 会哭)
# docker run --name test-mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -d mysql:5.6
# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
06b011faec62 mysql:5.6 "docker-entrypoint..." 2 seconds ago Up 1 second 0.0.0.0:3306->3306/tcp test-mysql

# 创建容器 test-phpmyadmin
# docker run --name test-phpmyadmin -p 8080:80 --link test-mysql:db -d phpmyadmin/phpmyadmin:latest
# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
61d649adb46f phpmyadmin/phpmyadmin:latest "/run.sh superviso..." 3 seconds ago Up 1 second 9000/tcp, 0.0.0.0:8080->80/tcp test-phpmyadmin
06b011faec62 mysql:5.6 "docker-entrypoint..." 2 minutes ago Up 2 minutes 0.0.0.0:3306->3306/tcp test-mysql

方法2: network

# 创建网络 net-mysql
# docker network create net-mysql

# 创建容器 test-mysql 并加入网络 net-mysql
# docker run --restart always --name test-mysql -e MYSQL_USER=root -e MYSQL_PASSWORD=root -e MYSQL_ROOT_PASSWORD=root -p 3306:3306 --network net-mysql -d mysql:5.6

# 创建容器 test-phpmyadmin 并加入网络 net-mysql
# docker run --name test-phpmyadmin -e MYSQL_USER=root -e MYSQL_PASSWORD=root -e MYSQL_ROOT_PASSWORD=root -e PMA_HOST=test-mysql -p 8080:80 --network net-mysql -d phpmyadmin/phpmyadmin:latest

# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3360662bd083 phpmyadmin/phpmyadmin:latest "/run.sh superviso..." 12 seconds ago Up 5 seconds 9000/tcp, 0.0.0.0:8080->80/tcp test-phpmyadmin
134c981b41f3 mysql:5.6 "docker-entrypoint..." 19 seconds ago Up Less than a second 0.0.0.0:3306->3306/tcp test-mysql

方法3: docker-compose.yml

docker-compose.yml 内容:

version: "2"
services:
mysql:
image: mysql:5.6
container_name: test-mysql
restart: always
ports:
- "3306:3306"
environment:
MYSQL_USER: "root"
MYSQL_PASSWORD: "root"
MYSQL_ROOT_PASSWORD: "root"
networks:
- net-mysql

phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
container_name: test-phpmyadmin
ports:
- "8080:80"
environment:
MYSQL_USER: "root"
MYSQL_PASSWORD: "root"
MYSQL_ROOT_PASSWORD: "root"
PMA_HOST: test-mysql
networks:
- net-mysql

networks:
net-mysql:

# docker-compose up -d
# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a1fdbba2ee85 phpmyadmin/phpmyadmin:latest "/run.sh superviso..." 12 seconds ago Up 9 seconds 9000/tcp, 0.0.0.0:8080->80/tcp test-phpmyadmin
61f4177a92f1 mysql:5.6 "docker-entrypoint..." 12 seconds ago Up 10 seconds 0.0.0.0:3306->3306/tcp test-mysql

打开浏览器, 输入 localhost:8080 即可访问 phpmyadmin 界面, 帐号密码都是 root
---------------------
作者:Gekkoou
来源:CSDN
原文:https://blog.csdn.net/Gekkoou/article/details/80897309
版权声明:本文为博主原创文章,转载请附上博文链接!

以上是关于[转]docker 部署 mysql + phpmyadmin 3种方法的主要内容,如果未能解决你的问题,请参考以下文章

Docker安装mysql5.7

转 docker 部署 kafka

Docker部署JavaWeb项目实战(转)

mysql可以部署到docker吗

(转)Spring Boot 2 :使用 Docker 部署 Spring Boot

Docker —— 用于统一开发和部署的轻量级 Linux 容器转