[转]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
版权声明:本文为博主原创文章,转载请附上博文链接!

转载于:https://www.cnblogs.com/freeliver54/p/10481629.html

你可能感兴趣的:([转]docker 部署 mysql + phpmyadmin 3种方法)