That's easily manageable if you setup a docker-compose.yml
having both containers within the same network:
version: '3'
services:
# Containers
my_wp_container:
# ...
# Container config goes here
# ...
networks:
# Make sure both containers are in the same network
- my_network_name
links:
# "Linking" containers makes it easy to refer to one container from another
- my_mysql_container
my_mysql_container:
# ...
# Container config goes here
# ...
container_name: my_mysql_container
networks:
- my_network_name
networks:
# No additional configuration is required for the network other than
# creating it; You are of course free to customize it to your needs
my_network_name:
Running docker-compose up
will spin up both containers simultaneously. Your WordPress container (my_wp_container
) can reach MySQL easily as my_mysql_container
is now a host alias know to WP's container.
Once both containers are running, try SSH'ing into my_wp_container
and running:
ping my_mysql_container
You should see that one container can reach the other within it's docker network!