Asp.net core with linux docker container

霸气de小男生 提交于 2019-12-13 17:40:37

问题


For a asp.net core project template in VS 2017, there are docker-compose.ci.build.yml:

version: '3'

services:
  ci-build:
    image: microsoft/aspnetcore-build:1.0-2.0
    volumes:
      - .:/src
    working_dir: /src
    command: /bin/bash -c "dotnet restore ./WebAppCoreDockerTest.sln && dotnet publish ./WebAppCoreDockerTest.sln -c Release -o ./obj/Docker/publish"

docker-compose.yml:

version: '3'

services:
  webappcoredockertest:
    image: webappcoredockertest
    ports:
      - 8080:80
    build:
      context: ./WebAppCoreDockerTest
      dockerfile: Dockerfile

and Dockerfile:

FROM microsoft/aspnetcore:2.0
ARG source
WORKDIR /app
EXPOSE 80
RUN echo "Oh dang look at that $source"
COPY ${source:-obj/Docker/publish} .
ENTRYPOINT ["dotnet", "WebAppCoreDockerTest.dll"]

The Dockerfile uses the files in obj/Docker/publish (copied to container) if source argument is null and docker-compose.ci.build.yml puhlishs project to obj/Docker/publish, I assume they are related.

So the question is How to use them together? (docker-compose.ci.build.yml publishes files to obj/Docker/publish and Dockerfile use published files)


回答1:


The docker-compose.ci.build.yml file is for building the project, as you mentioned. It uses the aspnetcore-build base image which is much heftier than the aspnetcore image used by the Dockerfile. The Dockerfile gets used by the build section of the docker-compose.yml file.

Everything works together with these two steps:

  1. docker-compose -f docker-compose.ci.build.yml run ci-build
  2. docker-compose up --build

The -f option in the first command allows you to specify a compose file other than the default docker-compose.yml.



来源:https://stackoverflow.com/questions/47278497/asp-net-core-with-linux-docker-container

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!