Docker 简明教程
Docker - Setting ASP.Net
ASP.Net 是 Microsoft 为开发服务器端应用程序提供的标准 Web 开发框架。由于 ASP.Net 已经存在很长时间,用于开发,因此 Docker 确保它支持 ASP.Net。
ASP.Net is the standard web development framework that is provided by Microsoft for developing server-side applications. Since ASP.Net has been around for quite a long time for development, Docker has ensured that it has support for ASP.Net.
在本章中,我们将了解启动并运行 ASP.Net 的 Docker 容器的各个步骤。
In this chapter, we will see the various steps for getting the Docker container for ASP.Net up and running.
Prerequisites
以下步骤必须首先用于运行 ASP.Net。
The following steps need to be carried out first for running ASP.Net.
Step 1 - 由于这只能在 Windows 系统上运行,因此首先需要确保拥有 Windows 10 或 Window Server 2016。
Step 1 − Since this can only run on Windows systems, you first need to ensure that you have either Windows 10 or Window Server 2016.
Step 2 - 接下来,确保在 Windows 系统上安装了 Hyper-V 和容器。要安装 Hyper-V 和容器,可以转至启用或禁用 Windows 功能。然后确保勾选 Hyper-V 选项和容器,并点击确定按钮。
Step 2 − Next, ensure that Hyper-V is and Containers are installed on the Windows system. To install Hyper–V and Containers, you can go to Turn Windows Features ON or OFF. Then ensure the Hyper-V option and Containers is checked and click the OK button.
系统可能需要在此操作后重启。
The system might require a restart after this operation.
Step 3 - 接下来,需要使用以下 Powershell 命令安装 Docker 的 1.13.0rc4 版本。以下命令将下载此版本并将其存储在临时位置。
Step 3 − Next, you need to use the following Powershell command to install the 1.13.0rc4 version of Docker. The following command will download this and store it in the temp location.
Invoke-WebRequest "https://test.docker.com/builds/Windows/x86_64/docker-1.13.0-
rc4.zip" -OutFile "$env:TEMP\docker-1.13.0-rc4.zip" –UseBasicParsing
Step 4 - 接下来,需要使用以下 powershell 命令展开归档文件。
Step 4 − Next, you need to expand the archive using the following powershell command.
Expand-Archive -Path "$env:TEMP\docker-1.13.0-rc4.zip" -DestinationPath $env:ProgramFiles
Step 5 - 接下来,需要使用以下 powershell 命令将 Docker 文件添加到环境变量。
Step 5 − Next, you need to add the Docker Files to the environment variable using the following powershell command.
$env:path += ";$env:ProgramFiles\Docker"
Step 6 - 接下来,需要使用以下 powershell 命令注册 Docker 守护进程服务。
Step 6 − Next, you need to register the Docker Daemon Service using the following powershell command.
dockerd --register-service
Step 7 - 最后,可以使用以下命令启动 docker daemon 。
Step 7 − Finally, you can start the docker daemon using the following command.
Start-Service Docker
在 powershell 中使用 docker version 命令验证 docker daemon 是否正常工作
Use the docker version command in powershell to verify that the docker daemon is working
Installing the ASP.Net Container
让我们看一看如何安装 ASP.Net 容器。
Let’s see how to install the ASP.Net container.
Step 1 - 第一步是从 Docker Hub 中拉取映像。登录 Docker Hub 时,将能够搜索并看到 Microsoft/aspnet 的映像,如下所示。只需在搜索框中输入 asp ,并点击搜索结果中出现的 Microsoft/aspnet 链接。
Step 1 − The first step is to pull the image from Docker Hub. When you log into Docker Hub, you will be able to search and see the image for Microsoft/aspnet as shown below. Just type in asp in the search box and click on the Microsoft/aspnet link which comes up in the search results.
Step 2 - 将看到 Docker Hub 中存储库详细信息中的 ASP.Net 的 Docker pull 命令。
Step 2 − You will see that the Docker pull command for ASP.Net in the details of the repository in Docker Hub.
Step 3 - 转到 Docker 主机并为 microsoft/aspnet 映像运行 Docker pull 命令。请注意,图像非常大,大约接近 4.2 GB。
Step 3 − Go to Docker Host and run the Docker pull command for the microsoft/aspnet image. Note that the image is pretty large, somewhere close to 4.2 GB.
Step 4 - 现在转到以下位置 https://github.com/Microsoft/aspnet-docker 并下载整个 Git 存储库。
Step 4 − Now go to the following location https://github.com/Microsoft/aspnet-docker and download the entire Git repository.
Step 5 - 在你的 C 盘创建名为 App 的文件夹。然后将 4.6.2/sample 文件夹中的内容复制到你的 C 盘。转到示例目录的 Docker File 并且发出以下命令 −
Step 5 − Create a folder called App in your C drive. Then copy the contents from the 4.6.2/sample folder to your C drive. Go the Docker File in the sample directory and issue the following command −
docker build –t aspnet-site-new –build-arg site_root=/
需要对上述命令注意以下几点 −
The following points need to be noted about the above command −
-
It builds a new image called aspnet-site-new from the Docker File.
-
The root path is set to the localpath folder.
Step 6 - 现在是时候运行容器了。它可以通过使用以下命令来完成 −
Step 6 − Now it’s time to run the container. It can be done using the following command −
docker run –d –p 8000:80 –name my-running-site-new aspnet-site-new
Step 7 - 你现在在 Docker 容器中运行 IIS。要找到 Docker 容器的 IP 地址,你可以像下面显示的那样发出 Docker inspect 命令。
Step 7 − You will now have IIS running in the Docker container. To find the IP Address of the Docker container, you can issue the Docker inspect command as shown below.