0

I have a dockerfile that looks like this:

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-alpine AS base

ENV ASPNETCORE_URLS=http://+:50777
EXPOSE 50777

FROM mcr.microsoft.com/dotnet/core/sdk:2.2-alpine AS build-env

COPY . /app
RUN dotnet restore

WORKDIR /app

ARG ASPNETCORE_ENVIRONMENT="Production"
ARG DATABASE_CONN_STRING="Server=tcp:mssqldb,1433; Database=test; User=sa; Password=test123;"
ARG ALLOWED_CORS=http://localhost:3000
ARG DOTNET_RUNNING_IN_CONTAINER=true

WORKDIR /app/backend
RUN dotnet publish -c Release -o /app/out

FROM base as final

WORKDIR /app
COPY --from=build-env /app/out ./out

WORKDIR /app/out

ENTRYPOINT ["dotnet", "test.project.dll"]

The project uses a database container and a backend container, exposing port 50777 for interaction with the APIs.

Given the dockerfile above, the build completes successfully, and the app is running in the container, but I can't reach the backend APIs.

Now I understood that ENV is used when the container is run, and the ARG are used during building, so what could be the reason why I cannot connect to it?

[EDIT]

Docker run command:

docker run -d --name api -p 50777:50777 -it test-image tail -f /dev/null
El Fred
  • 330
  • 1
  • 7
  • 23
  • Can you share your `docker run` command (and in particular its `-p` option)? – David Maze May 23 '19 at 03:30
  • @DavidMaze Added to the post! – El Fred May 23 '19 at 04:00
  • How are your `ARG` values being consumed (particularly `DATABASE_CONN_STRING`)? There are no explicit references to these. Are they being used implicitly by `dotnet`? Where is the database? localhost? Is `mssqldb` its hostname? Can the container resolve `mssqldb` if so? The `localhost` reference in the container refers to the container not your host. Is that what you intend? – DazWilkin May 23 '19 at 04:19
  • Why is this placed in the `base` stage? It appears that it's not used until later (if at all). I'm unfamiliar with the use of "+" to reference loopback or all local IPv4s (?). As above, I'm unclear where this (env) variable is consumed but, it *may* be that it's localhost (on the container) and that's probably not what you want. – DazWilkin May 23 '19 at 04:28
  • ```DATABASE_CONN_STRING``` is used by dotnet during build. The database is on localhost, with 'mssqldb' being the container name. The container is able to connect to the database. The ```ALLOWED_CORS``` should point to the outside, so the browser can connect without having CORS header issues on the host's localhost. – El Fred May 23 '19 at 04:31

0 Answers0