1. Introduction
-
Docker official documents , Docker Chinese documents, the update will lag behind the official documents
-
what
Docker
isDocker
It is an application打包
, tool分发
, and部署
tool. It can also be understood as a lightweight virtual machine. It only virtualizes the operating environment required by the software, and does not need any extras. A normal virtual machine is a complete and huge system, including various software whether it is necessary or not.打包
: It is to package the dependencies, third-party libraries, and software required for software operation into one安装包
.分发
: You can安装包
upload the packaged .部署
: Take安装包
, you can run the application with one command, and automatically simulate the exact same operating environment, no matter where you areWindows/Mac/Linux
.
-
feature comparison
characteristic Ordinary virtual machine Docker
Cross-platform Usually only run on desktop-class systems, e.g. Windows/Mac
not on a server without a GUIThere are many supported systems, all kinds of windows
andLinux
are supportedperformance High performance loss and high memory usage, because the entire system is virtualized Good performance, only the operating environment required by the virtual software, minimizing useless configuration automation need to install everything manually One command can automatically deploy the required environment stability The stability is not high, and the difference between different systems is large Good stability, different systems are deployed in the same way
2. Installation
-
docker installation , docker-compose installation , docker quick start, including detailed steps such as windows installation
-
Desktop version: https://www.docker.com/products/docker-desktop
-
Server version: https://docs.docker.com/engine/install/#server
-
docker
After the installation is successful, you can use$ docker -v
to check whether the installation is successful. -
docker-compose
After the installation is successful, you can use$ docker-compose -v
to check whether the installation is successful.Notice:
Except when
Linux
installing ondocker
, it will not be installed automaticallydocker-compose
, and other platforms (window
,mac
) will be automatically installeddocker-compose
.After installation
docker
, you can$ docker-compose -v
check whether it is installed by the waydocker-compose
. If it is not installed, you can install it according to the official website. -
After the installation is successful, in the desktop version, you only need to start it to use normally. Even if the configuration is modified, you can restart the software. In the server version, you need to start
systemctl
or restart:# 前面的 sudo 可更具情况进行添加 # 将 docker 加入开机自启动的列表 $ sudo systemctl enable docker # 启动 $ sudo systemctl start docker # 停止 $ sudo systemctl stop docker # 重启 $ sudo systemctl restart docker # 查看状态 $ sudo systemctl status docker
-
-
If it is in
Windows
the environment, you also need to configureWSL
the environment:-
Open
Windows 虚拟化
andLinux 子系统(WSL2)
, attached: docker windows installation and other detailed steps . -
Ubuntu(乌班图)
It is an operating system based onDebian
desktop applicationsLinux
, which can be searched and downloaded online in the application, or installed through commands. -
The command install (default install
ubuntu linux
) must be run onWindows 10 版本 2004
and above (build19041
and above) orWindows 11
to use the following:# 安装好 ubuntu 后,并启动,会要求输入账号密码 $ wsl --install # 上面等于下面,默认安装就是 Ubuntu $ wsl --install -d Ubuntu # 输出 正在安装: Ubuntu 已安装 Ubuntu。 正在启动 Ubuntu... Installing, this may take a few minutes... Please create a default UNIX user account. The username does not need to match your Windows username. For more information visit: <https://aka.ms/wslusers> Enter new UNIX username: xxxx New password: Retype new password: passwd: password updated successfully Installation successful! To run a command as administrator (user "root"), use "sudo <command>". ...
After installation, how to enter
ubuntu
?1. You can
cmd/PowerShell
execute$ ubuntu
the command in to enterubuntu
.2. In the system search, search for
ubuntu
the application and open it.
-
mirror configuration
-
mirror list
Mirror attribution mirror address Docker
Chinese official mirrorhttps://registry.docker-cn.com DaoCloud
mirror sitehttp://f1361db2.m.daocloud.io Azure
China Mirrorhttps://dockerhub.azk8s.cn HKUST Mirror Station https://docker.mirrors.ustc.edu.cn Ali Cloud https://<your_code>.mirror.aliyuncs.com You need to register an account to get a private one, here is someone else’s https://ud6340vz.mirror.aliyuncs.com Qiniu Yun https://reg-mirror.qiniu.com NetEase Cloud https://hub-mirror.c.163.com Tencent Cloud https://mirror.ccs.tencentyun.com -
mirror format
// 单个 "registry-mirrors": ["https://registry.docker-cn.com"] // 可以支持多个 "registry-mirrors": ["https://registry.docker-cn.com", "https://dockerhub.azk8s.cn", ...]
-
Configure mirroring:
# 方法一【使用命令修改配置】 # 1.运行以下命令来编辑 Docker 配置文件: $ sudo vim /etc/docker/daemon.json # 2.将以下内容复制到文件中,文件中有对象则去掉 {} 拷贝进去: { "registry-mirrors": ["https://registry.docker-cn.com"] } # 3. 保存并关闭文件。 # 4. 重启Docker服务: $ sudo systemctl restart docker # 5. 完成后,可以通过运行以下命令来验证是否成功: $ docker info # 6. 注意:如果是从其他镜像源获取镜像,需要将 https://registry.docker-cn.com 替换为相应的镜像源地址。 # 方法二:【使用 Docker Desktop 界面修改】 # 1.在 Docker Desktop 的状态栏上右键单击图标,选择 Settings。 # 2. 在 Docker Engine 选项卡中,找到 Registry mirrors 并单击 + 按钮。 # 3. 输入新的镜像源地址。 "registry-mirrors": ["https://registry.docker-cn.com"] # 4. 单击 Apply & restart 保存更改并重启服务。 # 5. 如果按钮自带重启,则不需要管,没有 restart 则需重启 Docker 服务。 # 6. 完成后,可以通过运行以下命令来验证是否成功: $ docker info
-
View current mirror
$ docker info
Execute the above command to see if there is any in the output information
Registry Mirrors
. If there is no default, it means a foreign mirror. If there is, it means that there is a custom mirror address:... Registry Mirrors: https://registry.docker-cn.com/
-
Three, use
-
Common commands
# 运行容器 $ docker run ... # 查看当前运行中的容器 $ docker ps # 查看镜像列表 $ docker images # 从仓库中拉取镜像 $ docker pull # 删除指定 id 的容器 $ docker rm <container-id> # 停止/启动指定 id 的容器 $ docker stop/start <container-id> # 删除指定 id 的镜像 $ docker rmi <image-id> # 查看 volume 列表 $ docker volume ls # 查看网络列表 $ docker network ls ......
-
Docker
Command command list: https://docs.docker.com/engine/reference/commandline/run/ -
Docker
Official mirror warehouse: https://hub.docker.com/For example: search
redis
, download and run.$ docker run -d -p 6379:6379 --name redis redis:latest -d # 表示可后台运行容器(守护式运行) -p # 宿主机端口:docker容器端口,将容器端口映射到宿主机上,通过宿主机访问内部端口 --name # 给要运行的容器起的名字 redis:latest # 指定版本 -it # 表示与容器进行交互式启动 /bin/bash # 交互路径 -v # 将容器内的指定文件夹挂载到宿主机对应位置 ......
-
docker-compose
way to runExample: Search
wordpress
, which can be run viadocker-compose.yml
download.Create a new one
docker-compose.yml
, copy the content in and save it, and then execute the installation command in this directory$ docker-compose up -d
After the installation is complete, you can access