First, you need to install Docker on your Mac
Download link: https://download.docker.com/mac/stable/Docker.dmg
Or check someone else's installation tutorial
How to install will not be elaborated here.
Open Docker
Enter the command
docker run -d --rm -p 8000:80 --name aspnetcore_sample microsoft/dotnet-samples:aspnetapp #Method 1
1 | docker run -it --rm -p 8000:80 --name aspnetcore_sample microsoft/dotnet-samples:aspnetapp #Method 2 |
Note:
- -it runs and enters the container, which occupies the terminal
- -d runs the container in the background, -d should not be used with -it together. It is recommended to use the first method to avoid occupying the terminal as we need to enter other commands later.
- You can also omit -d and open a new command window.
Wait a moment
The result is as shown in the figure
Finally, a string of characters is output.
Command explanation
docker run run
-i run the container in interactive mode, usually used with -t. After running the container, you will enter this container (system).
-d run the container in the background (to avoid occupying the terminal), and return the container ID.
--rm automatically delete the container after it exits. It cannot be used with -d. For convenience, the author used -d.
-p 8000:80 custom port external port:container port. If you want Docker to assign automatically, just use -P.
View running containers or check images
Input
docker images //View the list of downloaded images
Input
docker ps //View running containers
You can see the running containers.
Open the website
Open (if you used -p 8000:80 )
The result is as shown in the figure
文章评论