First try. net core 2.0 and dockercore in docker

Source: Internet
Author: User
Tags dotnet docker ps

First try. net core 2.0 and dockercore in docker

. Net core cross-platform with Linux, cannot be without docker ...... A series of articles on the Internet, especially docker has a Chinese official website: https://www.docker-cn.com /. The above is very clear. Here is only the operation record. The operating environment is Ubuntu 16.04 and docker.

I. Refer to the official website to install docker, website: https://docs.docker-cn.com/engine/installation/linux/docker-ce/ubuntu/

1、sudo apt-get remove docker docker-engine docker.io2、sudo apt-get update3、sudo apt-get install \    apt-transport-https \    ca-certificates \    curl \    software-properties-common4、curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -5、sudo apt-key fingerprint 0EBFCD886、sudo add-apt-repository \   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \   $(lsb_release -cs) \   stable"7、sudo apt-get update8、sudo apt-get install docker-ce9、docker --help10、sudo docker info

The preceding descriptions are detailed on the website.

2. Install microsoft/dotnet Images

1. pull microsoft/dotnet (default: latest) command: sudo docker pull microsoft/dotnet

He reported an error as soon as he got up. He cracked down ...... You can configure image acceleration.

2. You need to modify the/etc/docker/daemon. json file to configure image acceleration.

/Etc/docker cannot be opened. You do not have the permission to view the files in it. Modify the folder permission. Run the command: sudo chmod 777/etc/docker to create a daemon. json command: sudo vi/etc/docker/daemon. json

The newly created daemon. json file cannot be accessed. Modify the permission. Command: sudo chmod 777/etc/docker/daemon. json

If the above lock is lost, you can modify daemon. json and enter the following content:

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

Restart docker and run the following command: sudo systemctl restart docker.

Run the following hello world trainer command: sudo docker run hello-world and view the following image list: sudo docker images

Now you can rest assured that it is okay to pull microsoft/dotnet! Command: sudo docker pull microsoft/dotnet and check the current image: sudo docker images

This is a smooth download. Next we will use this image to create a new container and execute the command: sudo docker run-it microsoft/dotnet

// Reference http://www.runoob.com/docker/docker-run-command.htmldocker run: Create a new container and run a command-a stdin: Specify the standard input/output content type; optional STDIN/STDOUT/STDERR;-d: run the container in the background and return the container ID.-I: run the container in interactive mode. It is usually used together with-t.-t: Re-allocates a pseudo-input terminal for the container, -- name = "nginx-lb": specify a name for the container. -- dns 8.8.8.8: Specify the DNS server used by the container. By default, it is consistent with the host; -- dns-search example.com: Specifies the DNS search Domain Name of the container, which is consistent with the host by default.-h "mars": Specifies the hostname of the container;-e username = "ritchie": sets the environment variable; -- env-file = []: reads the environment variable from the specified file; -- cpuset = "0-2" or -- cpuset = ", 2": binds the container to the specified CPU for running; -m: sets the maximum memory usage for containers. -- net = "bridge": Specifies the network connection type of containers. The following four types are supported: bridge, host, none, and container; -- link = []: add a link to another container; -- expose = []: open a port or a group of ports;

Afterwards, we checked the dotnet version, created a "test1" directory, and created an MVC application under this directory. There is no difference between its directory discovery and non-container creation, in addition, we can use dotnet run to run the application:

 

Run the sudo docker run-it microsoft/dotnet command again, and then view all containers: sudo docker ps-a found that there are two containers based on microsoft/dotnet images, that is to say, every time you run docker run, a new container will be re-constructed that does not affect each other:

3. Host ASP. NET Core in a Docker container

1. Run the dotnet command on the local machine (win10): dotnet new mvc to create an MVC application and create the file "Dockerfile" in the root directory without a suffix. Enter the following content:

FROM microsoft/dotnet:latestWORKDIR /appCOPY bin/release/netcoreapp2.0/publish .ENV ASPNETCORE_URLS http://0.0.0.0:80ENTRYPOINT ["dotnet", "test1.dll"]

2. publish the application with the command dotnet publish-c release.

3. Copy the application to the Ubuntu Desktop

4. build a program image with the command: sudo docker build-t test1image. (remember this point)

5. run the generated image command: sudo docker run-p 8080: 80 -- name test1c1 test1image

6. view the image list and container list

7. Check the Ubuntu IP address (ifconfig), and check the running status on the local machine (win10 ).

8. Enter ctrl + c to stop the application.

9. view the container list (all containers-including stopped and started containers)

10. Restart the container "test1c1" and run the command: sudo docker start test1c1.

The website has been revived ......

In docker, try. net core. The last question is: can the MVC application (localhost: 5000) Run after entering the microsoft/dotnet image be accessed? How to access it? There may be deviations in understanding the first experience. If you have any knowledge, please don't hesitate to give me some advice. Thank you !!!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.