J'ai une API .NET Core 2.1 qui, lorsqu'elle est exécutée via Visual Studio dans Windows, reçoit un HTTP GET du navigateur et renvoie avec succès les données d'une base de données MySQL.
J'ai essayé d'ajouter l'API à un conteneur Docker (dans Ubuntu) - cela se construit, mais je ne peux pas accéder à l'API depuis le navigateur:
Ce que j'ai essayé :
docker-compose up
, the API starts, connects to the DB container, and it logs the result of an SQL query to a text file. So the problem is unlikely to be anything to do with the database.This might be relevant: In Windows, the API only works properly if you start it from Visual Studio. If you execute dotnet webapi.dll
, you get this output
...\netcoreapp2.1>dotnet webapi.dll
...
Now listening on: http://localhost:5000
Now listening on: https://localhost:5001
Application started. Press Ctrl+C to shut down.
So here it's not running on 44329; instead it's accessible via 5001 in the browser, where you get this message which is not chill at all: Clicking 'ADVANCED' allows you to continue to the API.
Here's the output from 'docker-compose up':
matt@Matt-Ubuntu:~/docker2$ docker-compose up
Starting docker2_mysql_1 ... done
Starting docker2_dbmodelmapper_1 ... done
Attaching to docker2_mysql_1, docker2_dbmodelmapper_1
... (mysql stuff) ...
dbmodelmapper_1 | Hosting environment: Production
dbmodelmapper_1 | Content root path: /app
dbmodelmapper_1 | Now listening on: http://[::]:80
dbmodelmapper_1 | Application started. Press Ctrl+C to shut down.
Seeing the port 80, I've tried connecting to that, without success.
The relevant container as shown by docker ps
is:
What kind of issue am I looking at here?
Comme l'ont souligné plusieurs personnes dans les commentaires (merci à sp0gg, Martin Ullrich et Daniel Lerps), l'API écoutait incorrectement sur le port 80.
La solution consistait à mapper le port 5000 à 44329 dans docker-compose.yml pour le conteneur API, et également à modifier le Dockerfile pour passer les ports en tant qu'arguments à dotnet lors du démarrage de l'API ASP.NET:
ENTRYPOINT ["dotnet", "webapi.dll", "--urls", "http://*:5000;http://*:5001"]
Cet article est collecté sur Internet, veuillez indiquer la source lors de la réimpression.
En cas d'infraction, veuillez [email protected] Supprimer.
laisse moi dire quelques mots