Deploy Asp.net core web application using docker--graphic tutorial

If you want to refer to this article for experiments, you can refer to the previous article, which is written in more detail about the simple operation of docker.

Pull the latest docker image of aspnetcore

Pull from Alibaba Cloud's docker image, because we have configured the docker image earlier.

[root@localhost ~]# docker pull microsoft/aspnetcore

Wait for the pull to succeed according to your internet speed.

[root@localhost ~]# docker images

Execute the above command, if you can see the aspnetcore image, it means the pull is successful.

 

If we want to pull the specified aspnetcore version, we can use the following command:

[root@localhost ~]# docker pull microsoft/aspnetcore:1.0

[root@localhost ~]# docker pull microsoft/aspnetcore:2.0

Make your own application mirror

1. Create a Dockerfile

We first create a Dockerfile in the temporary directory, and later our asp.net core web application will also be placed in the temporary directory.

[root@localhost ~]# cd /tmp

[root@localhost tmp]# vi Dockerfile

Copy the code below

FROM docker.io/microsoft/aspnetcore

WORKDIR /app

COPY ./songlou .

EXPOSE 8080

CMD ["dotnet", "SongLou.Web.dll"]

Copy the above five lines of code in, save and exit.

 

FROM represents the docker image that the new image depends on.

WORKDIR indicates which directory your asp.net core web application is placed in the container, here is the /app directory

COPY indicates which directory under the current system to copy, here is the songlou directory

EXPOSE indicates the exposed port number.

CMD represents the command to execute, that is, to run our own asp.net core web program.

 

Find a way to copy your asp.net core web publishing program to the /tmp temporary directory of the centos system

 

2. Create a mirror

[root@localhost tmp]# docker build -t mycore .

The following English symbol. cannot be removed, mycore represents your image name.

If Step1-Step5 appears, it means that the image was created successfully.

[root@localhost tmp]# docker images

Looking at all the mirrors again, we see:

In addition to the aspnetcore image we pulled from the official website, there is another image we created ourselves: mycore.

 

3. Run the container

[root@localhost tmp]# docker run --name mycore -p 8080:80 -d mycore

The first mycore is the container name, the second mycore is the image name

The ID of the new container will appear after execution:

2859330db3a5c6113b0ccdf6e9d78e7e36ea17f6c4de495514c4ec8901ed9218

 

4. Execute the curl command to visit our website

[root@localhost tmp]# curl http://localhost:8080

operation result:

{"str":"test","environmen":null,"username":null,"password":null}

[root@localhost tmp]# curl http://192.168.1.160:8080

The same result is seen with IP access:

{"str":"test","environmen":null,"username":null,"password":null}

Or enter in the browser address bar in the windows operating system: http://192.168.1.160:8080/ and see the same result.

 

So far you're done.

 

5. Enter the container

[root@localhost tmp]# docker exec -it mycore /bin/bash

The exec command can enter the docker container, and then use the centos operating system. operate inside.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325326348&siteId=291194637