Docker quick start – using docker desktop on Windows

Time:2020-9-15

https://mengz.me/posts/docker…

In the first part of this series – basic concepts and installation, we introduced the basic concepts of containers and how to install docker engine on Ubuntu (Linux) to develop containerized references
This article describes how to install and use docker on Windows system. Here, we mainly introduce how to install and use docker desktop on Windows 10. For versions below Windows 10, you can use docker toolbox, which will not be introduced here

Install docker desktop

Docker desktop – the fast way to container applications on your desktop, which is the official definition of docker. Docker desktop provides a desktop container development environment for windows and MAC. On Windows 10, docker desktop uses the Hyper-V virtualization technology of windows, so you need a computer with hardware virtualization turned on and installed with windows 10 professional version of the system, also need to open Hyper-V function, how to open Hyper-V on Windows 10, refer to here

A kind of Supplement_ : docker desktop supports windows 10 64 bit: professional, enterprise, education (build 15063 or above)

First, download the installation package of docker desktop on the windows system that meets the requirements- https://hub.docker.com/editio… The installation process is simple. You can double-click the downloaded installation directly, and you will be more prompted to install. At the beginning, we choose to use the Linux container (later we can change to use the windows container, and we will write a separate article to introduce the use of the windows container). During the installation process, the installation program will check whether the system meets the requirements. If not, the, Setup will report an error and end the installation

After installation, openstartMenu and selectDocker DesktopStart

Docker quick start - using docker desktop on Windows

Check the docker icon on the status bar, which will be displayed at the beginningstartingLoad, wait until the displayDocker Desktop is runningYou can use docker’s commands through terminals (such as powershield). Next, we will use windows 10’s PowerShell as the terminal for operation

Docker quick start - using docker desktop on Windows

Building and running containers

We will use a simple node application to illustrate how to build a container image and start a container on windows. First, we need to download the code base to our environment. Here we can clone the code base using git or download the code package directly

On windows, you can use git for windows or WSL of windows 10 to install an Ubuntu subsystem, and then install git in the terminal of the Ubuntu subsystem, and directly use git to clone the code. Here, I use the clone code library in the terminal of the Ubuntu subsystem to the local directory

Docker quick start - using docker desktop on Windows

As shown in the figure above, we cloned the code into theD:\gitrepos\hellonode\Directory, then switch to the PowerShell terminal and enter the directory. Open it with your favorite text editorhellonode\Dockerfile(vs code is used when recommending. The content is as follows

FROM node:12.2-alpine

MAINTAINER Mengz You <[email protected]>

WORKDIR /app

COPY package*.json ./

RUN npm install

COPY . .

EXPOSE 3000

CMD ["npm","start"]

Building a mirror image

Using this simple dockerfile to build the node application of the example, execute the following command in the PowerShell

docker image build -t hellnode:local .
docker image ls

As shown in the following figure, you will see the container image that is built

Docker quick start - using docker desktop on Windows

Run container

Then we use the built image to start an application container and execute the following command in the PowerShell

docker container run --name hellonode -d -p 3000:3000 hellonode:local
docker container ls

Docker quick start - using docker desktop on Windows

So we start a container and use itdocker contianer lsTo view the current container status, we can also use the docker desktop dashboard to view the container status graphically and perform some operations. To open the dashboard, click the docker desktop icon in the status bar and selectDashboardOpen, as shown in the following figure

Docker quick start - using docker desktop on Windows

On the dashboard, we can view container related information by UI operation, such as viewing container log, stopping / starting / restarting container, and entering container cli

When we run the container, we use the-p 3000:3000The 3000 port of container application is mapped to the local 3000 port, so we can directly access the local 3000 port to access the application

Docker quick start - using docker desktop on Windows

After that, we can use the following command to stop and delete the container

docker container stop hellonode
docker contianer rm hellonode

Push image to docker hub

If you need to push the built image to the docker hub, first log in to your docker hub account, click the docker desktop icon in the status bar, and selectSign in/Create Docker ID.., open the login window to log in

Docker quick start - using docker desktop on Windows

Then we execute it in PowerShell

docker image tag hellonode:local mengzyou/hellonode:v1.0
docker image push mengzyou/hellonode:v1.0

This will push the image to your warehouse on the docker hub

summary

Here is a brief introduction to how to use docker desktop to develop container applications on Windows 10. Docker desktop provides a good docker containerization tool for Windows users. In addition to using docker engine, docker Desktop also provides kubenetes function, can run a stand-alone k8s environment on windows, more information can read the official documents

Although docker desktop provides a visual management tool for windows, I still recommend using docker engine directly on Linux desktop. In Linux environment, if you want a UI management tool, I recommend using portal, a web-based container management tool