1

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)

2
  • 1
    Be careful with command: command: /bin/bash -c "dotnet restore ./WebAppCoreDockerTest.sln && dotnet publish ./WebAppCoreDockerTest.sln -c Release -o ./obj/Docker/publish" The current command will add test libraries into your docker image. I suggest excluding test projects from the build. Commented Nov 14, 2017 at 6:30
  • @Leonid Thanks, a question: the context of docker-compose.ci.build.yml command is in local or in container and copy files from /src/WebAppCoreDockerTest/obj/Docker/publish/ to local? Commented Nov 14, 2017 at 7:03

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, a question: the context of docker-compose.ci.build.yml command is in local or in container and copy files from /src/WebAppCoreDockerTest/obj/Docker/publish/ to local?
It is local context.
@Leonid If I change working_dir (working_dir:/src2), then it can't find the project, so it looks for project in src folder, but there isn't src folder in local, what's happen?
@Leonid Seems the context is in container. I add additional volumn (./result:/src/WebAppCoreDockerTest/obj/Docker/publish), then the published files will be copied from container to result folder in local.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.