我有一个带Postgres Db的ASP.NET Core API。我正在尝试对整个应用程序进行Docker化。
这是我的Dockerfile
:
# set base image as the dotnet 2.2 SDK.
FROM microsoft/dotnet:2.2-sdk AS build-env
# set the working directory for any RUN, CMD, ENTRYPOINT, COPY and ADD
# instructions that follows the WORKDIR instruction.
WORKDIR /app
# our current working directory within the container is /app
# we now copy all the files (from local machine) to /app (in the container).
COPY . ./
# again, on the container (we are in /app folder)
# we now publish the project into a folder called 'out'.
RUN dotnet publish Bejebeje.Api/Bejebeje.Api.csproj -c Release -o out
# set base image as the dotnet 2.2 runtime.
FROM microsoft/dotnet:2.2-aspnetcore-runtime AS runtime
# local variable
ARG customport
# temporary test to make sure the variable is coming through.
RUN echo "ASPNETCORE_URLS -> $customport"
# telling the application what port to run on.
ENV ASPNETCORE_URLS=$customport
# set the working directory for any RUN, CMD, ENTRYPOINT, COPY and ADD
# instructions that follows the WORKDIR instruction.
WORKDIR /app
# copy the contents of /app/out in the `build-env` and paste it in the
# `/app` directory of the new runtime container.
COPY --from=build-env /app/Bejebeje.Api/out .
# set the entry point into the application.
ENTRYPOINT ["dotnet", "Bejebeje.Api.dll", "-seed"]
这是我的docker-compose.yml
:
version: "3.7"
services:
bejebeje-api:
build:
context: .
dockerfile: ./Bejebeje.Api/Dockerfile
args:
- customport=http://*5005
labels:
com.bejebeje.description: "Bejebeje's API"
image: bejebeje-api:latest
ports:
- "5005:5005"
env_file:
- ./variables.env
depends_on:
- database
database:
image: postgres
ports:
- "8002:5432"
volumes:
- data-volume:/var/lib/postgresql/data
env_file:
- ./variables.env
volumes:
data-volume:
我首先运行docker-compose build
,我可以看到
Step 7/12 : RUN echo "ASPNETCORE_URLS -> $customport"
---> Running in cd127d488021
ASPNETCORE_URLS -> http://*5005
因此我的自定义参数通过了,但是当我运行docker-compose up
时,应用程序仍在端口80
而非5005
上运行。
我的variables.env
具有以下内容:
FrontendCorsOrigin=http://localhost:1234
ApiName=bejebeje-api
Authority=http://localhost:5000
Database__DefaultConnectionString=Server=database;Port=5432;Database=DbName;User Id=postgres;Password=awesomePass;
POSTGRES_PASSWORD=awesomePass
POSTGRES_DB=DbName
我在做什么错了?