2017-05-25 407 views
1

使用docker-compose启动一个wordpress容器,但在该容器内我想连接到AWS上的RDS mysql实例。我能够设置WordPress,但无法连接到数据库。我试着将DB_NAME变量改为_DATABASE。我也是能够使用mysql命令行从我的MAC,使其中工程从Docker容器与Wordpress连接到RDS Mysql

version: '2' 

services: 
    wordpress: 
    image: wordpress:latest 
    ports: 
     - "8000:80" 
    restart: always 
    environment: 
     MYSQL_HOST: "endpoint" 
     MYSQL_USER: "user" 
     MYSQL_PASSWORD: "pass" 
     MYSQL_DB_NAME: "wordpress_docker" 
     MYSQL_PORT: 3306 
    volumes: 
     - ${HOME}:/var/lib/mysql 
+0

什么**主机**你提供吗? RDS实例地址? –

+0

对于主机,我使用长端点 '.us-west-1.rds.amazonaws.com' – Patrick

回答

2

根据使用WordPress的documentation

环境名称应该是连接,

WORDPRESS_DB_HOST=... (defaults to the IP and port of the linked mysql container) 
WORDPRESS_DB_USER=... (defaults to "root") 
WORDPRESS_DB_PASSWORD=... (defaults to the value of the MYSQL_ROOT_PASSWORD environment variable from the linked mysql container) 
WORDPRESS_DB_NAME=... (defaults to "wordpress") 
WORDPRESS_TABLE_PREFIX=... (defaults to "", only set this when you need to override the default table prefix in wp-config.php) 
+0

我明白非常感谢! – Patrick