Use of Docker containers under CentOS7 .net Core 2.2
First, using yum installation (CentOS 7 below)
Docker system requirements CentOS kernel version higher than 3.10, see this page prerequisite to verify your CentOS version supports Docker.
By uname -r to see your current kernel version command
Second, the installation Docker
From March 2017 began docker is divided into two branches on the basis of the original version: Docker CE and Docker EE.
Docker CE community that is free version, Docker EE namely Enterprise Edition, emphasis on security, but need to pay to use.
1, remove the old version
$ sudo yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-selinux \ docker-engine-selinux \ docker-engine
2, install the necessary system tools
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
3, add the software source information
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
4, update yum cache
sudo yum makecache fast
5, mounting Docker-ce
sudo yum -y install docker-ce
6, start the background service Docker
sudo systemctl start docker
7, test run hello-world
[root@localhost /]# docker run hello-world
Two, Asp.Net Core2.2 Web program
dockerfile your application is deployed to a plain text file the necessary configuration information on the docker, just without an extension of it
Set Makefile property [ always copy ]
Dockerfile content
FROM microsoft/dotnet:2.2-aspnetcore-runtime #基础镜像为dotnetcore MAINTAINER demo #作者 LABEL description="this is a test website" #描述 LABEL version="1.0" #描述 WORKDIR /app #工作目录 COPY . . #将当前目录下的文件,复制到WORKDIR目录 EXPOSE 8888 #容器暴漏8888端口,与上一步设置的端口一致 ENTRYPOINT ["dotnet","demo.dll"] #运行容器的命令
修改Program.cs文件
namespace demo { public class Program { public static void Main(string[] args) { CreateWebHostBuilder(args).Build().Run(); } public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseUrls("http://*:8888") .UseStartup<Startup>(); } }
发布,文件系统
默认位置
demo\bin\Release\netcoreapp2.2\publish
三、构建镜像
1、切换到发布目录
[root@localhost publish]
2、修改Makefile文件
指定容器对外暴露端口80。注意,COPY .后面有空格,表示是当前位置,意思是从当前位置复制文件到/publish目录下
3、根据当前目录下dockerfile配置文件,进行打包
[root@localhost publish]# docker build -t demo .
4、查看我们打包好的镜像。
[root@localhost publish]# docker images
Fourth, run docker container
[root@localhost publish]# docker run -d -p 8888:8888 demo
-p port mapping is performed between the host and the container, (- p host port: the port of the container)
-d command, the vessel will continue to run even turn off the terminal window
Inspection docker container is running successfully
Five test
This confidential transmission of IP Centos
Within Centos access localhost on it
Explanation
1、配置docker开机启动
systemctl enable docker
2, confirm that the container has run
[root@localhost /]# docker ps
CONTAINER ID: Container ID
NAMES: container name automatically assigned
Use docker logs command in the container, the container to view the standard output
3, start / stop container
[Root @ localhost /] # docker start / stop container vessel name or id
4, restart the docker services, such errors encountered
The reason is docker hung up service
systemctl restart docker