本文介绍了带Linux Docker容器的Asp.net核心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于VS 2017中的asp.net核心项目模板,有do​​cker-compose.ci.build.yml:

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:

docker-compose.yml:

version: '3'

services:
  webappcoredockertest:
    image: webappcoredockertest
    ports:
      - 8080:80
    build:
      context: ./WebAppCoreDockerTest
      dockerfile: 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"]

Dockerfile使用文件在obj / Docker / publish(复制到容器)中,如果源参数为null,并且docker-compose.ci.build.yml将项目推向obj / Docker / publish,我认为它们是相关的。

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.

所以问题是如何一起使用? (docker-compose.ci.build.yml将文件发布到obj / Docker / publish,并且Dockerfile使用已发布的文件)

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)

推荐答案

The如您所述, docker-compose.ci.build.yml 文件用于构建项目。它使用 aspnetcore-build 基本映像,该映像比Dockerfile使用的 aspnetcore 映像要重得多。 Dockerfile 被docker-compose.yml文件的 build 部分使用。

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运行ci-build

  2. docker-compose up --build

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

第一个命令中的 -f 选项可让您指定撰写默认文件 docker-compose.yml 以外的文件。

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

这篇关于带Linux Docker容器的Asp.net核心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 20:46