一个容器装 wordpress,一个容器装 mysql, 以下两个版本的 docker-compose.yml
都ok,第2个版本多了一个 phpadmin 容器, 用于查看 mysql。
- 版本1,
version: "3.9" services: db: image: mysql:5.7 volumes: - db_data:/var/lib/mysql restart: always environment: MYSQL_ROOT_PASSWORD: somewordpress MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWORD: wordpress wordpress: depends_on: - db image: wordpress:latest volumes: - wordpress_data:/var/www/html - ./wp-content:/var/www/html/wp-content ports: - "8000:80" restart: always environment: WORDPRESS_DB_HOST: db WORDPRESS_DB_USER: wordpress WORDPRESS_DB_PASSWORD: wordpress WORDPRESS_DB_NAME: wordpress volumes: db_data: wordpress_data:
- 版本 2:
version: '3' services: db: image: mysql:5.7 volumes: - db_data:/var/lib/mysql restart: always environment: MYSQL_ROOT_PASSWORD: password MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWORD: wordpress networks: - wpsite phpmyadmin: depends_on: - db image: phpmyadmin/phpmyadmin restart: always ports: - '8080:80' environment: PMA_HOST: db MYSQL_ROOT_PASSWORD: password networks: - wpsite wordpress: depends_on: - db image: wordpress:latest ports: - '8000:80' restart: always volumes: [ './wp-files:/var/www/html' ] environment: WORDPRESS_DB_HOST: db:3306 WORDPRESS_DB_USER: wordpress WORDPRESS_DB_PASSWORD: wordpress networks: - wpsite networks: wpsite: volumes: db_data:
这一个版本的 networks
没有必要设置,用 docker-compose 启动的容器默认都属于同一个网络。
工程文件夹里只需要一个 docker-compose.yml
文件就够。
运行 docker compose up -d
启动容器
运行 docker compose down -v
停止并删除容器,--volumes
或 -v
用于删除卷。
在 docker-compose.yml
文件里指定的端口可以看到 wordpress 容器成功启动:
如果是第2个版本,还可以看到 phpadmin 界面, 8080 端口:
https://www.youtube.com/watch?v=pYhLEV-sRpY
原文链接:https://blog.csdn.net/ftell/article/details/128254216?ops_request_misc=&request_id=a33692c262e541fbad46a1a655f78274&biz_id=&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~koosearch~default-24-128254216-null-null.268%5Ev1%5Econtrol&utm_term=docker%E3%80%81wordpress%E3%80%81wordpress%E5%BB%BA%E7%AB%99%E3%80%81wordpress%E4%B8%BB%E9%A2%98%E3%80%81%E5%AE%B9%E5%99%A8%E9%95%9C%E5%83%8F%E3%80%81