docker configuration dotnet core project

1. Install docker

  First look yum update

yum update

  installation

yum install -y docker

  start up

systemctl start docker # start 
systemctl status docker # View state

  Modify mirroring configuration file, instead ustc mirror

we /etc/docker/daemon.json

  Add the following code

{
    "registry-mirrors":["https://docker.mirrors.ustc.edu.cn"]
}

  Restart

daemon- systemctl reload # reload the configuration 
systemctl restart docker # restart Docker 
Docker info # View information, have the most at the end of the configuration information Registry Mirrors

  Try, got me a mirror

pull the Hello-world Docker 

Docker Search the Hello-world # pull before taking can look at what version

  If there is no open security group inbound rule, will not visit, jam, then an error occurs, remember to open (refer to cloud server)

docker images # View Mirror

  Try to run it

docker run hello-world  

  

 

 

   success! ! ! ! !

2. Install dotnet core 2.2 environment

  Very simple, a command to engage in

docker pull microsoft/dotnet:2.2-aspnetcore-runtime

3. Configure dotnet core project

  Create a local project, modify Program

    public class Program
    {
        public static void Main(string[] args)
        {
            CreateWebHostBuilder(args).Build().Run();
        }

        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseUrls("http://*:2202")
                .UseStartup<Startup>();
    }

  This is to specify the port, * is to allow linux to be able to access the site through the container curl, goes on to say

  The key point here, the new Dockerfile

In the Microsoft the FROM / DOTNET: 2.2 -aspnetcore- Runtime # 2-point stretch to take the mirror 
COPY. / The Data / www # from the local (that is, the project directory published) copy to this position mirrored 
WORKDIR / the Data / to access the www # position 
EXPOSE 2202  
EntryPoint [ " DOTNET " , " CoreDemo.dll " ]

  And set the properties to always copy / newer copy

  Publish and upload to linux, what directory to upload to decide for themselves

  cd to publish the root directory

Build Docker - . # t coredemo create a mirror, define their own name 

Docker RUN --name mycoredemo -p 2202 : 2202 -d # coredemo run and produce container, - name for the container name their own definition -p linux open ports for external access : -d port mirroring to mirror name

  You can now use curl to see if you can print Code

curl http://localhost:2202

  Other related operations

docker ps # show running container 

Docker PS - A # show all containers 

delete 

stop, remove the container, and then delete the image 

docker stop container id \ name 

Docker RM container id \ name 

Docker rmi image id \ name

 

Guess you like

Origin www.cnblogs.com/wskxy/p/11499829.html