Docker support for the VS2017-based implementation of an ASP.

Source: Internet
Author: User
Tags dotnet

Recently learning how to use Docker to deploy an ASP. NET Core site in a production environment, as a novice docer, where is it easier to get started? The first handwritten Docker profile (Docfile, DOCKER-COMPOSE.YML) is a frustrating one, thinking about the Visual Studio 2017 support for Docker, Maybe it's using it to automate the creation of Docker profiles, a preliminary experience Docker deployment is a quick way to get started, so it feels good to try it out.

1. There are 2 ways to enable VS2017 Docker support:

1.1 Select Enable Docker support when creating an ASP. NET Core Project

1.2 or add Docker support in an existing project (note: not a solution)

2. After adding Docker support, VS2017 will produce 4 Docker profiles and 1. dcproj files.

2.1 Dockfile

 from microsoft/aspnetcore:2.0ARG sourceworkdir /appEXPOSE COPY ${ Source:-obj/docker/publish}. entrypoint ["Dotnet", "Aspnetcore2-20170530.dll"]

2.2 Docker-compose.ci.build.yml

version: ' 3 'services:  ci-build:    image: microsoft/ aspnetcore-build:1.0-1.1    Volumes:      -.:/ SRC    working_dir:/src    command:/bin/bash-c "dotnet restore. Aspnetcore2-20170530.sln && dotnet Publish./aspnetcore2-20170530.sln-c release-o./obj/docker/publish "

(Note: Due to the project of ASP. NET Core 2.0, you need to change the above microsoft/aspnetcore-build:1.0-1.1 to microsoft/aspnetcore-build:2.0)

2.3 docker-compose.yml

version: ' 3 'services:  aspnetcore2-20170530:    image: aspnetcore2-20170530    build:      context:./aspnetcore2-20170530      dockerfile: Dockerfile

2.4 docker-compose.override.yml

version: ' 3 'services:  aspnetcore2-20170530:    Environment:      - Aspnetcore_environment=development    Ports:      -"80"

(Note: In order to be able to access the site outside the container, you need to modify the above Ports section configuration, here the "80" to "8,008:80")

3. Create 2 container releases (dotnet publish) with Docker on another 1 Linux servers and run the ASP. NET Core Site

3.1 Checking out an ASP. NET Core project on a Linux machine (Docker installed)

3.2 Based on the docker-compose.ci.build.yml configuration file microsoft/aspnetcore-build:2.0 image is created for publishing ASP. Container for Site

# docker-compose--file  docker-compose.ci.build.yml uppulling ci-build (microsoft/aspnetcore-build:2.0) ... 2.0:pulling from Microsoft/aspnetcore-build ... status:downloaded newer image for Microsoft/aspnetcore-build:2.0...starting src_ci-build_1 ... Starting src_ci-build_1 ... doneattaching to src_ci-build_1...src_ci-build_1 exited with code 0

3.3 According to Docker-compose.yml + docker-compose.override.yml based on microsoft/aspnetcore:2.0 Image (configuration from Dockerfile) creates a container to run the ASP.

# Docker-compose upstarting src_cnblogs.cache.webapi_1 ... Starting src_cnblogs.cache.webapi_1 ... doneattaching to src_cnblogs.cache.webapi_1cnblogs.cache.webapi_1  | Hosting Environment:Developmentcnblogs.cache.webapi_1  | Content Root path:/appcnblogs.cache.webapi_1  | Now Listening on:http://[::]:80cnblogs.cache.webapi_1  | Application started. Press CTRL + C to shut down.

At this point, the 8008 port of the Linux server allows access to the ASP. NET Core site running in the Docker container.

This is a quick and easy way to experience the deployment of an ASP. NET Core site with Docker is really a good place to start.

Docker support for the VS2017-based implementation of an ASP.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.