尝试在Windows的Docker上安装Wordpress

时间:2018-12-23 05:31:15

标签: php linux wordpress docker

我在Windows上使用docker,我刚刚安装了它,并且我有以下stack.yml文件,该文件返回一个错误,我会将其放在yml文件下面。我不了解是什么原因导致我在运行命令docker-compose -f stack.yml up时无法正常工作,请有人帮忙。提前谢谢。

version: '3.1'

services:

  wordpress:
    image: wordpress
    restart: always
    ports:
      - 8080:80
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: exampleuser
      WORDPRESS_DB_PASSWORD: examplepass
      WORDPRESS_DB_NAME: exampledb

  db:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_DATABASE: exampledb
      MYSQL_USER: exampleuser
      MYSQL_PASSWORD: examplepass
      MYSQL_RANDOM_ROOT_PASSWORD: '1'

错误

wordpress_1  | Complete! WordPress has been successfully copied to /var/www/html
wordpress_1  |
wordpress_1  | MySQL Connection Error: (2002) Connection refused
wordpress_1  |
wordpress_1  | Warning: mysqli::__construct(): (HY000/2002): Connection refused in Standard input code on line 22
wordpress_1  |
wordpress_1  | Warning: mysqli::__construct(): (HY000/2002): Connection refused in Standard input code on line 22
wordpress_1  |
wordpress_1  | MySQL Connection Error: (2002) Connection refused
wordpress_1  |
wordpress_1  | Warning: mysqli::__construct(): (HY000/2002): Connection refused in Standard input code on line 22

1 个答案:

答案 0 :(得分:1)

该应用需要事先运行db。 在WordPress容器之前,为WordPress服务添加depends_on值,以确保数据库处于启动状态。 容器中的MySQL服务应尽快启动。

version: '3.1'

services:

  wordpress:
    image: wordpress
    restart: always
    depends_on:
      - db
    ports:
      - 8080:80
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: exampleuser
      WORDPRESS_DB_PASSWORD: examplepass
      WORDPRESS_DB_NAME: exampledb

  db:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_DATABASE: exampledb
      MYSQL_USER: exampleuser
      MYSQL_PASSWORD: examplepass
      MYSQL_RANDOM_ROOT_PASSWORD: '1'