php WordPress的docker-compose

rsaldnfx  于 2023-11-16  发布在  PHP
关注(0)|答案(1)|浏览(94)

我有一个docker-compose文件

version: '2'
services:
  php:
    image: wordpress:5.5-php7.4-apache
    volumes:
      - ~/.composer-docker/cache:/root/.composer/cache:delegated
      - ./htdocs/:/var/www/html:delegated
    ports:
      - '80:80'
    networks:
      - my-network

  wpcli:
    image: wordpress:cli-2-php7.4
    user: xfs
    depends_on:
      - db
      - php
    volumes:
      - ./htdocs:/var/www/html
    environment:
      WORDPRESS_DB_USER: user
      WORDPRESS_DB_PASSWORD: password

  db:
    image: mysql:5.7
    restart: always
    environment:
      - DB_CONNECTION=mysql
      - DB_HOST=db:3306
      - MYSQL_DATABASE=mds
      - MYSQL_USER=user
      - MYSQL_PASSWORD=password
      - MYSQL_ROOT_PASSWORD=password
    ports:
      - '3306:3306'
    expose:
      - '3306'
    volumes:
      - my-db:/var/lib/mysql
    #volumes:
    #  - ~/mysql:/var/lib/mysql
    networks:
      - my-network

  composer_installation:
    container_name: composer_installation
    image: composer:1.10.19
    command: ["composer", "install"]
    volumes:
      - ./htdocs/:/app

volumes:
  my-db:
networks:
  my-network:
    driver: bridge

字符串
和php,mysql和wordpress工作正常,我可以从我的主机连接到数据库与客户端没有问题使用0.0.0.0:3306,但当我尝试使用wp-blog我可以看到在日志中
错误:建立数据库连接时出错。
我换了几个小时的音量,但运气不好,
任何小费欢迎

sqougxex

sqougxex1#

我知道这很晚了,但为了子孙后代:
wpcli容器缺少网络条目,因此无法按名称找到db容器。您需要添加

networks:
      - my-network

字符串
docker-compose.yml的wptom容器部分

相关问题