Installation and use of docker in win10

Matthew 2021-01-21 16:01:30
installation use docker win10 win

docker Installation

Environmental preparation

Docker for Windows It's a Docker Community Edition(CE) Applications .Docker for Windows The installation package is included in Windows Running on the system Docker Everything you need . If you don't want to install virtual machines , Want to be directly in your Windows Operating system installation and learning to use docker, So you first have to see if your system satisfies Docker for Windows Installation and use requirements of .

  1. Docker for Windows The current version of runs on 64 position Windows 10 Pro, pro 、 Enterprise edition and Education Edition (1607 Anniversary update , edition 14393 Or later ) On .Ps: The home version is no good , If you're the home version , First, upgrade to the professional version , Crack the professional version and recommend an address : , Second, installation Docker Toolbox, Baidu Online
  2. If you're satisfied Docker for Windows The environmental conditions of our country have changed , Then first check whether the virtualization of the computer is turned on : Go to task manager (ctrl+alt+delete), Click performance ->cpu , See if virtualization is enabled , If virtualization is disabled , Then you need to restart the computer to enter bios Turn on Virtualization ( Our hair's notebook cpu All support virtualization , Enter on restart bios Press esc -> Press again f12 -> To turn on Virtualization )
  3. Turn on virtualization and restart , Go to task manager to see if virtualization is enabled .

  1. Then go to the control panel of the computer -> Program -> Enable or close Windows function -> hold Hyper-v On the hook , When enabled, the computer will restart , You can download and install it later Docker for Windows 了 .

Download and install

  1. Go to the website Download and install . I have the stable version installed . There's nothing to pay attention to during the installation .

  1. After startup, it will appear in the lower right corner of the desktop , After the mouse is put on, it will be displayed Docker is running Indicates successful startup , The first time you install and enable it, it seems that a Docker Cloud Login screen , Register and log in , Use and git It's kind of similar , Sure pull Images and so on

docker To get started

Start using

  1. Check Docker,Compose and Machine Version of

  1. Check version information , And ensure docker Order normal operation
  1. function docker run hello-world To test from Docker Hub Pull the image and start the container

  1. Use command docker run -it ubuntu bash Run one Ubuntu Containers , I've pulled this container before , It's probably tens of megabytes , So it's directly enabled , Input exit Command to stop the container

  1. Run the command docker run -d -p 80:80 –name webserver nginx Start a Dockerized webserver Will download nginx Container image and start it , Then open the browser and type http://localhost

  1. function docker ps command , Check container details

  1. Stop or remove containers and images . If you want to stop the web server , Input :docker stop webserver And then restart it docker start webserver. To stop and delete a running container with a single command , Please type the : docker rm -f webserver. This will delete the container , But it's not nginx Images . You can list local images docker images. You may want to keep some pictures , So you don't have to start from Docker Hub They're out of the box . To delete images that are no longer needed , Please use docker rmi The heel image ID Or image name . for example docker rmi nginx

docker Common configuration of

stay PowerShell Set in tab Key auto completion ( It's all about cmd.exe)

  1. Start a new PowerShell( Run as an administrator ). Search for PowerShell, Right click , Then choose to run as Administrator . stay PowerShell Type... At the prompt :Set-ExecutionPolicy RemoteSigned
  2. Check that the policy settings are correct , function :get-executionpolicy, Should return to RemoteSigned.
  3. install posh-dockerPowerShell Module to complete automatically Docker command , type :Install-Module posh-docker perhaps , To install the module only for the current user , type :Install-Module -Scope CurrentUser posh-docker
  4. After installation , Only for the present PowerShell Enable autocomplete , Input :Import-Module posh-docker
  5. In order to be in all PowerShell Keep... In conversation Tab Completion status $PROFILE, Please be there. PowerShell Enter... At the prompt :
if (-Not (Test-Path $PROFILE)) {
New-Item $PROFILE –Type File –Force
Add-Content $PROFILE "`nImport-Module posh-docker"

This will create a PROFILE If it doesn't exist , And add this line to the file :Import-Module posh-docker To check that the file has been created correctly , Or just edit it manually , Please be there. PowerShell Type the following :Notepad PROFILE Open a new PowerShell conversation . Now? , When you type the first few letters, press Tab key ,Docker command ( As in the beginning , stop it , Run and its options ) And container and image names should now be done automatically .


Find the one in the lower right corner docker Icon , Right click selection settings go in

  1. General: Here are the settings docker Boot from boot , Check for updates when the application starts , Publish usage statistics
  1. Advanced: Distribute cpu Number and memory
  1. Daemon:Docker for windows10 Alicloud image can be configured , To Sign up for an account , Log in and select accelerator from the list , Copy and paste your accelerator address to Daemon Of Registry mirrors in

use Dockerfile Define a mirror image

in the past , If you're going to start writing a Python Applications , Your first step is to install a Python Runtime . however , This will cause the environment on your machine to meet certain conditions so that your application can run . Use Docker, You can put a portable Python The runtime as an image , No installation required . then , Your build can put the foundation Python Images are included with the application code , Make sure your application , Dependencies and runtime run together . These portable images are created by a company called Dockerfile It's defined by

New catalog file

Create an empty directory , My name is docker, Then create three new files in it :Dockerfile,,requirements.txt

The contents of the three documents are designed as :

# Use an official Python runtime as a parent image
FROM python:2.7-slim
# Set the working directory to /app
# Copy the current directory contents into the container at /app
ADD . /app
# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host -r requirements.txt
# Make port 80 available to the world outside this container
# Define environment variable
# Run when the container launches
CMD ["python", ""]
from flask import Flask
from redis import Redis, RedisError
import os
import socket
# Connect to Redis
redis = Redis(host="redis", db=0, socket_connect_timeout=2, socket_timeout=2)
app = Flask(__name__)
def hello():
visits = redis.incr("counter")
except RedisError:
visits = "<i>cannot connect to Redis, counter disabled</i>"
html = "<h3>Hello {name}!</h3>" \
"<b>Hostname:</b> {hostname}<br/>" \
"<b>Visits:</b> {visits}"
return html.format(name=os.getenv("NAME", "world"), hostname=socket.gethostname(), visits=visits)
if __name__ == "__main__":'', port=80)
3. requirements.txt:

Build a mirror image

stay docker Open in directory cmd.exe Run the command ( Make sure you can find Dockerfile file , The image is called friendlyhello):docker build -t friendlyhello. ps: Don't fall behind the point behind the line above , Once in a pit .. The order includes the following point

Then execute the order : docker images

Run the image program : docker run -p 4000:80 friendlyhello

You can see Python Providing message for application however , This message comes from inside the container , It doesn't know that we're going to port the container 80 Mapping to 4000, To open up URL: http://localhost:4000

Stop the container

First, press... After following the above steps ctrl+c Exit at the terminal , This doesn't mean that the mirror is stopped type docker container ls Lists running containers

Run the command :docker container stop <Container NAME or ID> Stop container . otherwise , When you rerun the container in the next step , You will receive an error response .

contact Docker Hub Common operations of

Log in to Docker Hub

I've already said that ,docker and git There are similarities in the operation of , therefore docker There are also remote warehouses , If you have already registered and logged in docker cloud, So visit the website : Create a repository inside , Otherwise, register first .

push Mirror image

I created a local friendlyhello Mirror image , Now it's time to push To Their own docker hub In your repository , First :

  1. Sign in docker hub ( I've already logged in .. Log in again )

  1. Mark image : Put the image in wangliguo And mark it as a repository test
  1. Look at the mirror image :

  1. Release image ( Push the mirror )

  1. Docker Hub Look at the image on the screen :
  1. Extract and run the image from the remote repository : Now when the remote repository has a mirror , Then it can be extracted from the remote repository and run


In distributed applications , Different parts of the application are called “ service ”. for example , Imagine a video sharing site , It may include services for storing application data in a database , Video transcoding service for users to upload things , For front-end services and so on . Service is really just “ Containers in production ”. The service only runs one image , But it encodes the way the mirror works - Which port should be used , How many copies should the container run , So that the service has the required capacity , And so on . The scaling service changes the number of container instances that run the software , Thus, more computing resources are allocated to the services in the process . Use Docker Platform definition , Running and extending services is very simple - Just write a docker-compose.yml File can .

Create a docker-compose.yml file

type :

version: "3"
# replace username/repo:tag with your name and image details
image: 15433/wangliguo:test
replicas: 5
cpus: "0.1"
memory: 50M
condition: on-failure
- "80:80"
- webnet

Pull from the repository in the previous step tag. Running the image 5 An instance is called as a service web, Limit every use of , most 10% Of CPU( Across all cores ) and 50MB Of RAM. If one fails , Restart the container now . Connect the port on the host 80 Mapping to web port 80. To guide the web Containers are shared through a load balanced network 80 port webnet.( In the internal , The container itself will web Publish on a temporary port to port 80). webnet Use default settings ( This is a load balanced overlay network ) Defining network .

Run a new load balancing application

Run the command first :docker swarm init

And then run the command :docker stack deploy -c docker-compose.yml getstartedlab Call it getstartedlab

The service stack is running on this host 5 A container instance to deploy the image Run the command to see :docker service ls

A single container running in a service is called a task , You can see there's one up there getstartedlab_web Service for Run the command docker service ps getstartedlab_web View tasks under this service :

If only all containers in the system are listed , The task will also be displayed , But not filtered by services : Run the command :docker container ls -q

Then open the browser , type http://localhost

Click refresh many times , You can find Hostname Change of , Choose... In a circular way 5 One of the tasks to respond to . Containers ID Will be the same as the previous command (docker container ls -q) Match the output of .

Change the application

For example, change docker-compose.yml Medium replicas value , Save the changes and rerun docker stack deploy Command to update the application :

Run the command : docker stack deploy -c docker-compose.yml getstartedlab

Docker Will do an in place update , And then rerun docker container ls -q To see the reconfigured deployed instances

As you can see, it was 6 individual , Now it is 7 individual , Just a better task ps: The computer also runs the previous steps from docker hub The task that is being pulled and running in the middle , So you'll see 6 And 7 individual

Shut down applications and groups

close applications docker stack rm getstartedlab

Now that all tasks in the service are closed, run the command later : docker container ls -q


Learn about clusters

swarm Is to run Docker And join a group of machines in a cluster . But now they will be executed by Cluster Administrator on the cluster . The machines in a group can be physical or virtual . After joining the group , They're called nodes . Swarm Administrators can use a variety of policies to run containers , such as “ The emptiest node ”(emptiest node) - It uses containers to fill the least used machines . or “ overall situation ”, This ensures that each machine can only get one instance of the specified container . You can indicate swarm manager stay Compose These strategies are used in the document . The group manager is the only machine in the group that can execute your commands , Or authorize other machines to join the group as workers . Workers provide the ability to , There's no right to tell any other machine what it can and can't do . up to now , Previously, it was used in single host mode on the local machine Docker. however Docker You can also switch to cluster mode , That's why clustering is used . Enable group mode to make the current machine a group manager . be Docker Will run the commands executed on the cluster you are managing , Not just on the current machine .

Create a cluster

A group consists of multiple nodes , It can be a physical machine or a virtual machine . The basic concept is simple : function docker swarm init Enable group mode , Make the current machine a group manager , then docker swarm join Running on other machines , Let them join the group as workers . Next, we will use virtual machines to quickly create a two machine cluster , And turn it into a cluster . step :

  1. Run as an administrator cmd.exe Here must be the administrator running , Otherwise, the subsequent operation authority is not enough
  1. function docker swarm init Enable group mode , Make the current machine a group manager , then docker swarm join Running on other machines , Let them join the group as workers .
  2. start-up Hyper-V Manager Click Start windows Management tools Hyper-V Manager
  1. Click virtual switch manager in the menu on the right
  1. Click create virtual switch of type external network , Give it a name myswitch, And check box to share your host's active network adapter
  1. Use the node management tool to create several virtual machines docker-machine: docker-machine create -d hyperv –hyperv-virtual-switch “myswitch” myvm1 docker-machine create -d hyperv –hyperv-virtual-switch “myswitch” myvm2

I've created it before , So I'm going to build two more :myvm3 and myvm4 docker-machine create -d hyperv –hyperv-virtual-switch “myswitch” myvm3 docker-machine create -d hyperv –hyperv-virtual-switch “myswitch” myvm4

  1. Now we've created two virtual machines , Named as myvm3 and myvm4. Use command docker-machine ls List machines and get their IP Address .

Initialize the group and add nodes

  1. Use the command first docker-machine ssh myvm3
  1. Run another as an administrator cmd.exe. And then run the command :docker-machine ssh myvm4
docker swarm join --token SWMTKN-1-0csyw4yz6uxob90h0b8ejoimimrgisiuy9t2ugm8c1mxfvxf99-7q7w5jw1mrjk1jlri2bcgqmu8

With the order to leave the group :docker swarm leave

Deploying applications on a cluster

  1. docker-machine by swarm The manager configures a shell Run the command :docker-machine env myvm3

Pay attention to the last line I am here @FOR /f "tokens=*" %i IN ('docker-machine env myvm3') DO @%i Copy and paste to run it

  1. stay swarm Deploy the application on the manager Before we deploy docker-compose.yml Service as an example

After entering the directory, execute the above command :

Then execute the order docker stack ps getstartedlab View service details :

If you find that state There is shutdown The situation of ( It is also possible that the number of instances in your picture is greater than the number defined in your service file , These are the pits I've climbed , Now what I define here is 6, The picture is also 6,), That should be the chapter in which you have run the command before : docker stack deploy -c docker-compose.yml getstartedlab Instead of putting getstartedlab Remove It's time to execute the order :docker stack rm getstartedlab hold getstartedlab Remove Ps: I am a d,c All disks have executed this command , Because before running docker stack deploy -c docker-compose.yml getstartedlab The order is in d At the time of the dish And then rerun :docker stack deploy -c docker-compose.yml getstartedlab and docker stack ps getstartedlab Just fine

  1. The browser accesses the cluster's web address : As shown in the red box , Access any of them on a browser , And then refresh , Will see 6 A possible container ID, They're all random cycles , Shows load balancing
  1. Some other orders :
 For example, if it changes docker-compose.yml After the document , Carry out orders :
docker stack deploy -c docker-compose.yml getstartedlab
Just run it again to deploy the changes
For example, the removal of applications mentioned earlier :docker stack rm getstartedlab
Leave the group :docker swarm leave –force
Restart the stopped virtual machine , perform :
docker-machine start <machine-name>

Participation of this paper Tencent cloud media sharing plan , You are welcome to join us , share .


  1. 【计算机网络 12(1),尚学堂马士兵Java视频教程
  2. 【程序猿历程,史上最全的Java面试题集锦在这里
  3. 【程序猿历程(1),Javaweb视频教程百度云
  4. Notes on MySQL 45 lectures (1-7)
  5. [computer network 12 (1), Shang Xuetang Ma soldier java video tutorial
  6. The most complete collection of Java interview questions in history is here
  7. [process of program ape (1), JavaWeb video tutorial, baidu cloud
  8. Notes on MySQL 45 lectures (1-7)
  9. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  10. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  11. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  12. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  13. 【递归,Java传智播客笔记
  14. [recursion, Java intelligence podcast notes
  15. [adhere to painting for 386 days] the beginning of spring of 24 solar terms
  16. K8S系列第八篇(Service、EndPoints以及高可用kubeadm部署)
  17. K8s Series Part 8 (service, endpoints and high availability kubeadm deployment)
  18. 【重识 HTML (3),350道Java面试真题分享
  19. 【重识 HTML (2),Java并发编程必会的多线程你竟然还不会
  20. 【重识 HTML (1),二本Java小菜鸟4面字节跳动被秒成渣渣
  21. [re recognize HTML (3) and share 350 real Java interview questions
  22. [re recognize HTML (2). Multithreading is a must for Java Concurrent Programming. How dare you not
  23. [re recognize HTML (1), two Java rookies' 4-sided bytes beat and become slag in seconds
  24. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  25. RPC 1: how to develop RPC framework from scratch
  26. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  27. RPC 1: how to develop RPC framework from scratch
  28. 一次性捋清楚吧,对乱糟糟的,Spring事务扩展机制
  29. 一文彻底弄懂如何选择抽象类还是接口,连续四年百度Java岗必问面试题
  30. Redis常用命令
  31. 一双拖鞋引发的血案,狂神说Java系列笔记
  32. 一、mysql基础安装
  33. 一位程序员的独白:尽管我一生坎坷,Java框架面试基础
  34. Clear it all at once. For the messy, spring transaction extension mechanism
  35. A thorough understanding of how to choose abstract classes or interfaces, baidu Java post must ask interview questions for four consecutive years
  36. Redis common commands
  37. A pair of slippers triggered the murder, crazy God said java series notes
  38. 1、 MySQL basic installation
  39. Monologue of a programmer: despite my ups and downs in my life, Java framework is the foundation of interview
  40. 【大厂面试】三面三问Spring循环依赖,请一定要把这篇看完(建议收藏)
  41. 一线互联网企业中,springboot入门项目
  42. 一篇文带你入门SSM框架Spring开发,帮你快速拿Offer
  43. 【面试资料】Java全集、微服务、大数据、数据结构与算法、机器学习知识最全总结,283页pdf
  44. 【leetcode刷题】24.数组中重复的数字——Java版
  45. 【leetcode刷题】23.对称二叉树——Java版
  46. 【leetcode刷题】22.二叉树的中序遍历——Java版
  47. 【leetcode刷题】21.三数之和——Java版
  48. 【leetcode刷题】20.最长回文子串——Java版
  49. 【leetcode刷题】19.回文链表——Java版
  50. 【leetcode刷题】18.反转链表——Java版
  51. 【leetcode刷题】17.相交链表——Java&python版
  52. 【leetcode刷题】16.环形链表——Java版
  53. 【leetcode刷题】15.汉明距离——Java版
  54. 【leetcode刷题】14.找到所有数组中消失的数字——Java版
  55. 【leetcode刷题】13.比特位计数——Java版
  56. oracle控制用户权限命令
  57. 三年Java开发,继阿里,鲁班二期Java架构师
  58. Oracle必须要启动的服务
  59. 万字长文!深入剖析HashMap,Java基础笔试题大全带答案
  60. 一问Kafka就心慌?我却凭着这份,图灵学院vip课程百度云