asp.net - Setup aspnetcore with MySQL database in docker -
i'm trying set docker-compose file container asp.net-core, mysql database , phpmyadmin. there no problem setting mysql-server, can access phpmyadmin. asp.net-core application running correctly , can access in browser.
however, not able make connection mysql database. application keeps returning:
unable connect of specified mysql hosts
the application connecting through connection string in appsettings.json.
{ "connectionstrings": { "flowerapiconnection": "server=localhost;userid=user;password=user;database=bloemenapi_db;convert 0 datetime=true" }, "logging": { "includescopes": false, "debug": { "loglevel": { "default": "warning" } }, "console": { "loglevel": { "default": "warning" } } } }
my guess in docker container app , mysql running can't seem find each other on localhost. tried using ip-adress of mysql container in connectionstring, did not work.
i'm using following docker-compose.yml , dockerfile.
version: '3' services: db: image: mysql restart: container_name: flowerapi-db environment: - mysql_user=root - mysql_password=user - mysql_root_password=user - mysql_database=bloemenapi_db ports: - "3306" phpmyadmin: image: phpmyadmin/phpmyadmin container_name: flowerapi-pma ports: - "81:80" external_links: - db:mysql environment: pma_host: "db" pma_port: 3306 web: image: flowerapi container_name: flowerapi-web build: context: ./flowerapi dockerfile: dockerfile ports: - "5000:80" links: - db depends_on: - db
dockerfile
from microsoft/aspnetcore:2.0 label name "flower-api" arg source workdir /app expose 5000/tcp copy ${source:-obj/docker/publish} . entrypoint ["dotnet", "flowerapi.dll"]
thanks help.
localhost inside each container, won't work. try connect using db
hostname, , port 3306
.
Comments
Post a Comment