Trying to use docker-compose.yml instead of starting the containers separately like so:
docker container run --name mysql -d -e MYSQL_RANDOM_ROOT_PASSWORD=yes -e MYSQL_DATABASE=currency -e MYSQL_USER=currency -e MYSQL_PASSWORD=currency mysql/mysql-server:5.7
docker run --name currency -d -p 8000:5000 --rm --link mysql:dbserver -e DATABASE_URL=mysql+pymysql://currency:currency@dbserver/currency currency:latest
When run separately, the flask app correctly finds the DATABASE_URL and uses mysql db.
The docker-compose.yml file which I used is below:
version: "2"
services:
mysql:
image: mysql/mysql-server:5.7
environment:
- MYSQL_RANDOM_ROOT_PASSWORD:yes
- MYSQL_DATABASE:currency
- MYSQL_USER:currency
- MYSQL_PASSWORD:currency
currency:
build: .
links:
- "mysql:dbserver"
ports:
- "8000:5000"
environment:
- DATABASE_URL:"mysql+pymysql://currency:currency@dbserver/currency"
When I use docker-compose.yml, it is not using the mysql db. I believe for some mistake in docker-compose.yml, the flask app is not able see the environment variable "DATABASE_URL". What is going wrong in the docker-compose.yml?