Reputation: 13
I would like to know how to set WORDPRESS_DB_HOST in docker-compose file.
wordpress:
image: wordpress
ports:
- 8080:80
environment:
WORDPRESS_DB_PASSWORD: example
WORDPRESS_DB_HOST: 192.168.99.100:3307
wordpress_db:
image: mariadb
environment:
MYSQL_ROOT_PASSWORD: example
ports:
- 3307:3306
volumes:
- /doc/wordpress_db:/var/lib/mysql
Here, "192.168.99.100" is my IP's docker machine. I would like to replace it by a dynamic value.
Thanks ! :)
Upvotes: 1
Views: 7685
Reputation: 2291
I'm not sure about version 1 of docker-compose, but I would do it like this:
version: '2'
services:
wordpress:
image: wordpress
ports:
- 8080:80
environment:
- WORDPRESS_DB_PASSWORD=example
- WORDPRESS_DB_HOST=wp_db
links:
- wordpress_db:wp_db
wordpress_db:
image: mariadb
environment:
- MYSQL_ROOT_PASSWORD=example
ports:
- 3307:3306
volumes:
- /doc/wordpress_db:/var/lib/mysql
The thing to note is the links
part. You can link the container to a container in another service. This allows you to reference the IP of the database with the alias wp_db
.
Upvotes: 2