Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
运行docker compose up时未使用ASPNETCORE_URL参数_Docker_Asp.net Core_Docker Compose - Fatal编程技术网

运行docker compose up时未使用ASPNETCORE_URL参数

运行docker compose up时未使用ASPNETCORE_URL参数,docker,asp.net-core,docker-compose,Docker,Asp.net Core,Docker Compose,我有一个带有Postgres Db的ASP.NET核心API。我正在尝试将整个应用程序归档 这是我的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 W

我有一个带有Postgres Db的ASP.NET核心API。我正在尝试将整个应用程序归档

这是我的
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

My
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


我做错了什么?

您可以共享variables.env文件的内容吗?您可以更改Dockerfile中的入口点并在其中运行“env”吗?这样,您可以在运行时查看所有环境变量。所有这些看起来都不错,但不知何故,您可能会错误地覆盖该变量。这是检查此问题的一种方法。我已将
variables.env
的内容添加到问题中。如果要在运行时使用此文件,应将env var添加到此文件中。端口名前面可能缺少冒号:`-customport=http://*:5005`是否可以共享variables.env文件的内容?是否可以更改Dockerfile并在其中运行“env”?这样,您可以在运行时查看所有环境变量。所有这些看起来都不错,但不知何故,您可能会错误地覆盖该变量。这是检查此问题的一种方法。我已将
variables.env
的内容添加到问题中。如果要在运行时使用此文件,应将env var添加到此文件中。端口名前面可能缺少冒号:`-customport=http://*:5005`