I’m a Docker newbie and I’m trying to compose a .NET Core 2.0 web API in a Ubuntu 18 host, using Docker 18.05.0-ce (build f150324) and these services:
1.SQL Server database
2.MySql database
3.Mongo database
My docker compose file provides these services from their respective images, as reported below. I configure the database admin users with envronment variables, as required, and override connection strings in my API app using environment variables, too.
All the services start OK, MySql included; yet, my app throws an exception when trying to connect to MySql: Application startup exception: MySql.Data.MySqlClient.MySqlException (0x80004005): Host '172.19.0.5' is not allowed to connect to this MySQL server
.
Could anyone suggest a solution? Here is my compose file:
version: '3.4'
services:
# SQL Server at default port (1433, redirect to e.g. 1403 in a machine
# with SQL Server installed).
lexminmssql:
image: microsoft/mssql-server-linux
container_name: sqlserver
environment:
ACCEPT_EULA: Y
SA_PASSWORD: "P4ss-W0rd!"
ports:
- 1433:1433
networks:
- lexminnetwork
# MongoDB - at default port (27017, just stop your host MongoDB server if any,
# or redirect it to another port).
lexminmongo:
image: mongo
container_name: mongo
ports:
- 27017:27017
networks:
- lexminnetwork
# MySql at default port (3306, redirect if required)
# https://github.com/docker-library/docs/tree/master/mysql#mysql_database
# https://docs.docker.com/samples/library/mysql/#environment-variables
lexminmysql:
image: mysql/mysql-server
container_name: mysql
environment:
# the password that will be set for the MySQL root superuser account
MYSQL_ROOT_PASSWORD: "password"
ports:
- 3306:3306
networks:
- lexminnetwork
# Web API
lexminapi:
image: naftis/lexminapi
ports:
- 58942:58942
depends_on:
- lexminmssql:
condition: service_healthy
- lexminmongo:
condition: service_healthy
- lexminmysql:
condition: service_healthy
build:
context: .
dockerfile: LexminApi/Dockerfile
environment:
# for Windows use : as separator, for non Windows use __
# (see https://github.com/aspnet/Configuration/issues/469)
DATA__DEFAULTCONNECTION__CONNECTIONSTRING: "Server=sqlserver\\sqlexpress,1433;Database=lexmin;User Id=SA;Password=P4ss-W0rd!;MultipleActiveResultSets=true"
SERILOG__CONNECTIONSTRING: "Server=sqlserver\\sqlexpress,1433;Database=lexmin;User Id=SA;Password=P4ss-W0rd!;MultipleActiveResultSets=true"
LEX__CONNECTIONSTRING: "mongodb://mongo:27017/lex_catalog"
ZAX__CONNECTIONSTRING: "Server=mysql;Database=zax_master;Uid=root;Pwd=password;SslMode=none"
# TODO: locate BIN directories in Linux
ENVIRONMENT__MONGODIRECTORY: ""
ENVIRONMENT__MYSQLDIRECTORY: ""
ENVIRONMENT__MYSQLDUMPUSER: "root"
ENVIRONMENT__MYSQLDUMPPASSWORD: "password"
networks:
- lexminnetwork
volumes:
- ./zax-users.xml:/etc/lexmin/zax-users.xml
# Web app
# TODO
networks:
lexminnetwork:
driver: bridge