Docker installation and deployment of Net Core implementation process analysis

Docker installation and deployment of Net Core implementation process analysis

1. Docker installation and settings

#Install CentOS and put the Docker package in the Extras software source. You can use it directly: yum install docker-io -y

#View the version of docker
docker -v

#Start the Docker service systemctl start docker.service

#Start the Docker service systemctl enable docker.service

#Check the startup status of the Docker service systemctl status docker.service

#Restart the Docker service systemctl restart docker.service

2. Create a new Net Core program

1. Create a new Net Core project. Note: Docker support is not enabled.

2. Publish the newly created project (target runtime: portable)

3. Create a new Dockerfile file in the published folder (without suffix)

The general contents are as follows:

FROM microsoft/dotnet:2.1-aspnetcore-runtime //Note that your version must match WORKDIR /app
COPY . . //Copy all files in the current directory (except the paths excluded by .dockerignore) to the /app directory of the image file.
EXPOSE 5000 //Port number (expose the container port 5000 to allow external connections to this port.)
//EXPOSE 443 //Https port is opened ENTRYPOINT ["dotnet", "DockerDemo5.dll"] //Change the running assembly to your own 

3. Upload the published project to the Linux server (CentOS)

1. Enter the release directory of the program

#Enter the release target of the program cd /data/web/mydocker

#Create an image file (-t parameter is used to specify the name of the image file, and a colon can be used to specify the label after it. PS: Note the last dot)
docker build -t aspnetcoredocker1.1 . 

#Generate a container. Each time you run it, a new container will be created (the 5000:5000 here means mapping port 5000 in the container to port 5000 on your host, with the container port at the end)
docker run -it -p 5000:5000 aspnetcoredocker1.1
#docker run -it -p 5000:5000 aspnetcoredocker1.1:TAG // The default TAG is latest 

2. Just access it directly

3. Automatically start the docker container (after the container exits or is powered off, docker can specify the restart strategy by using the --restart parameter when creating the container)

# Set the startup strategy docker run --restart always -it -p 5000:5000 aspnetcoredocker1.1

#If the container has been created, we want to change the restart policy of the container docker update --restart always 3ec28be7254a //Container ID


# --restart Multiple parameter values ​​select no to not automatically restart the container. (Default value)
on-failure The container exits when an error occurs (the container exit status is not 0) and restarts the container. You can specify the maximum number of restarts, such as: on-failure:10
Unless-stopped Restart the container only when the container has been stopped or Docker is stopped/restarted. Manual stop does not count. Always Restart the container only when the container has been stopped or Docker is stopped/restarted.

4. Docker related commands

Image files and container commands

#View all docker images

#Delete an image with imageid docker rmi [IMAE_ID] 

#Delete all images sudo docker rmi $(docker images -q) 


#View the running status of all containers docker ps -a  
docker container ls -all

#Delete a container with containerid (instance)
docker rm 6f0c67de4b72 

#Delete all containers docker rm $(sudo docker ps -a -q)

Container logs

#View the logs after the specified time, and only display the last 100 lines:
docker logs -f -t --since="2019-06-08" --tail=100 CONTAINER_ID

#View the log after a certain time:
docker logs -t --since="2019-06-08" CONTAINER_ID

#View logs for a certain period of time:
docker logs -t --since="2019-06-08" --until "2019-06-09" CONTAINER_ID

#View the logs for the last 30 minutes:
docker logs --since 30m CONTAINER_ID

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • .Net Core deploys Docker container
  • ASP.NET Core Development Docker Deployment
  • Complete steps for deploying Asp.net core applications with docker
  • Implementation of one-click deployment of Asp.net Core Jenkins Docker
  • .Net Core automated deployment: How to deploy dotnetcore applications using docker version of Jenkins
  • ASP.NET Core Docker deployment in detail
  • Deploy ASP.NET Core applications using Docker

<<:  Testing of hyperlink opening target

>>:  Solve the problem of not finding NULL from set operation to mysql not like

Recommend

Some conclusions on developing mobile websites

The mobile version of the website should at least...

VUE introduces the implementation of using G2 charts

Table of contents About G2 Chart use Complete cod...

Nginx local directory mapping implementation code example

Sometimes you need to access some static resource...

Using puppeteer to implement webpage screenshot function on linux (centos)

You may encounter the following problems when ins...

Detailed explanation of Redis master-slave replication practice using Docker

Table of contents 1. Background 2. Operation step...

The concept of MTR in MySQL

MTR stands for Mini-Transaction. As the name sugg...

Implementing long shadow of text in less in CSS3

This article mainly introduces how to implement l...

A brief discussion on whether CSS animation will be blocked by JS

The animation part of CSS will be blocked by JS, ...

How to use async and await correctly in JS loops

Table of contents Overview (Loop Mode - Common) D...

The vue project realizes drawing a watermark in a certain area

This article shares with you how to use Vue to dr...

What are the differences between xHTML and HTML tags?

All tags must be lowercase In XHTML, all tags must...

Vue-Element-Admin integrates its own interface to realize login jump

1. First look at the request configuration file, ...

Detailed analysis of each stage of nginx's http request processing

When writing the HTTP module of nginx, it is nece...

Several ways to improve the readability of web pages

1. Use contrasting colours. The contrast here ref...