0 Preface/Foreward
0.1 参考文档
Overview of Docker Desktop | Docker Docs (Docker Desktop使用手册)
0.1.1 Docker Dashboard
Before going any further, we want to highlight the Docker Dashboard, which gives you a quick view of the containers running on your machine. It prvovides you access to container logs, lets you get a shell inside the container, and allows you to easily manage container lifecycle (stop, remove, etc.).
0.1.2 What is a container?
Simply put, a container is another process on your machine that has been isolated from all other processes on the host machine. That isolation leverages kernel namespaces and cgroups, features that have been in Linux for a long time. Docker has worked to make these capabilities approachable and easy to use.
0.1.3 What is a container image?
When running a container, it uses an isolated filesystem. This custom filesystem is provided by a container image. Since the image contains the container's filesystem, it must include everyting needed to run the application - all dependencies, configuration, scripts, binaries, etc. The image also contains other configuration for the container, such environment variables, a default command to run, and other metadata.
0.2 Docker Desktop介绍
0.2.1 Overview
Docker Desktop is one-click-install application for your Mac, Linux, or Windows environment that lets you build, share, and run containerized applications and microservices.
It provides a straightforward GUI (Graphical User Interface) that lets you manage your containers, applications, and images directly from your machine.
Docker Desktop reduces the time spent on complex setups so you can focus on writing code. It takes care of port mappings, file system concerns, and other default settings, and is regularly updated with bug fixed and security updated.
What's included in Docker Desktop?
- Docker Engine
- Docker CLI clent
- Docker build
0.2.2 Docker Engine
Docker Engine is an open source containerization technology for building and containerizing your applications. Docker Engine acts as a client-server application with:
- A server with a long-running daemon process dockerd
- APIs which specify interfaces that programs can use to talk to and instrcut the Docker daemon.
- A command line interface (CLI) client docker
0.2.3 Docker Build
Docker build is one of Docker Engine's most used features. Whenever you are creating an image you are using Docker Build. Build is a key part of your software development life cycle allowing you to package and bundle your code and ship it anywhere.
Docker build is more than a command for buiding images, and it's not only about packaging your code. It's a whole ecosystem of tools and features that support not only common workflow tasks but also provides support for more complex and advanced scenarios.
1 安装
1.1 运行docker安装包
安装完Docker Desktop后,运行Docker Desktop,出现WSL 2安装不完整情况,具体情况如下:
解决方法:旧版 WSL 的手动安装步骤 | Microsoft Learn
也可以直接下载新的安装包,然后安装。https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi
1.2 开始使用Docker
1.2.1 Clone a repository
The Getting Started project is a simple GitHub repository which contains everyting you need to build an image and run it as a container.
Clone the repository by running Git in a container.
You can also type the command directly in a command line interface/application.
1.2.2 Build the image
A Docker image is a private file system just for your container. It provides all the files and code your container needs.
1.2.3 Run your first container
Start a container based on the image you built in the previous step. Running a container launches your application with private resources, securely isolated from the rest of your machine.
命令分析:
docker run -d -p 80:80 docker/getting-started
You will notice that a few flags being used, here is some more info on them:
- -d - run the container in detached mode (in the background/backend)
- -p 80:80 - map port 80 of the host to port 80 in the container
- docker/getting-started - the image to run
Pro tip: Professional tip (专业提示)
You can combine single character flags to shorten the full command. As an example, the command above could be written as:
docker run -dp 80:80 docker/getting-started
1.2.4 Share
You must be signed in to Docker Hub to share your image.
Save and share your image on Docker Hub to enable other users to easily download and run the image on any destiantion machine.
2 使用
2.1 启动Docker
注意:要启动Docker,需要登陆账号。
PS C:\Users\Andy.fan> docker run -d -p 80:80 docker/getting-started
Unable to find image 'docker/getting-started:latest' locally
latest: Pulling from docker/getting-started
c158987b0551: Pull complete
1e35f6679fab: Pull complete
cb9626c74200: Pull complete
b6334b6ace34: Pull complete
f1d1c9928c82: Pull complete
9b6f639ec6ea: Pull complete
ee68d3549ec8: Pull complete
33e0cbbb4673: Pull complete
4f7e34c2de10: Pull complete
Digest: sha256:d79336f4812b6547a53e735480dde67f8f8f7071b414fbd9297609ffb989abc1
Status: Downloaded newer image for docker/getting-started:latest
0130d63f7f0180c19450c9c03278bd1e56f19b6f86b6779ccf80bdd74f906341
PS C:\Users\Andy.fan>
2.2 为WSL distro激活Docker desktop
参考上面的建议文档:https://docs.docker.com/desktop/wsl/
根据上面提醒,在Docker Desktop设置界面:settings > Resources > WSL INTEGRATION
选中默认的WSL distro(可以按照多个发行版本),当前只安装了一个发行版本,所以Ubuntu-18.04就是默认的发行版本。
激活成功WSL Docker Desktop,输入docker命令,显示Usage 命令文本:
2.3 Docker Desktop启动的WSL distro
Docker Desktop 安装了两个special-purpose internal Linux distros:都不能用作通用开发
- docker-desktop:用来运行Docker engine (dockerd)
- docker-desktop-data:存储容器(containers)和镜像(image)。