Since the “link” directive has been deprecated, I was wondering how to connect to a mariadb instance on a non-default network when both the database and the monitor are running is separate networks. Here is what I got:
First I made sure I could get the link method to work as described on the docker Mariadb site.
Create the network
docker network create --driver bridge maria-bridge |
create the database on that network
docker run --network=maria-bridge --name some-mariadb -e \ MYSQL_ROOT_PASSWORD=my-secret-pw -d mariadb:latest |
create the monitor also on that network. Note that none of the env vars set by link have been set. Fior now, just hard code them
docker run -it --network maria-bridge \ -e MYSQL_ROOT_PASSWORD="my-secret-pw" \ --rm mariadb sh \ -c 'exec mysql -hsome-mariadb -P3306 -uroot -p"$MYSQL_ROOT_PASSWORD"' |