Docker 是一个跨平台的开源的 应用容器引擎 ,诞生于 2013 年初,基于 Go语言 并遵从 Apache2.0 协议开源, Docker 可以把它理解成虚拟机,但是 Docker 和传统虚拟化方式 有所不同 :传统虚拟机技术是虚拟出一套硬件后,在其上运行一个完整操作系统,在该系 \统上再运行所需应用进程;Docker 相比传统的虚拟化技术要 更轻量级 , Docker 容器内的应用程序是 直接运行 在 宿主内核中 的,容器内没有自己的内核,也没有进行硬件虚拟
因此 Docker 容器要比传统虚拟机 占用资源更小 、 系统支持量更大 、 启动速度更快 、 更容易维护和扩展Docker官网: https://hub.docker.com
除了刚才说的 Docker 容器要比传统虚拟机占用资源更小、系统支持量更大、启动速度更快、 更容易维护和扩展外,Docker 还是 世界领先的软件容器平台
docker 容器都是基于 linux 内核,所以学习 docker 必须具备 linux 基础,如果不会 linux 请参: 一些经常使用的linux命令, linux内存、cpu、进程、端口、硬盘管理, Linux 目录结构介绍
使用安装docker需要的最小内核是 3.10,Centos7 和 Centos8 都能满足要求,查看内核命令: uname -r
安装 docker 建议使用 win10
must be version 10.14 or newer
注意 :windows操作系统需要启用 Hyper-V 和适用 Linux 的子系统Hyper-V 是 微软开发的虚拟机 ,类似于 VMWare 或 VirtualBox , 仅适用于 Windows 10 ,这是 Docker Desktop for Windows 所使用的虚拟机,但是,这个虚拟机一旦启用, QEMU 、VirtualBox 或 VMWare Workstation 15 及以下版本将无法使用,如果必须在电脑上使用其他虚拟机(例如开发 Android 应用必须使用的模拟器),请不要使用 Hyper-V
下载软件包:https://docs.docker.com/engine/install/
双击软件,点击'下一步',安装即可
注意:此方法仅适用于 Windows 10 操作系统专业版、企业版、教育版和部分家庭版
如果第一次打开提示下面错误,请下载安装 wslupdatex64.mis后重启 docker
下载 wslupdatex64.mis 安装后重启 docker
鉴于国内网络问题,后续拉取 Docker 镜像十分缓慢,可以需要配置加速器来解决,可以使用阿里的镜像地址:https://02xz0m84.mirror.aliyuncs.com在任务栏点击 Docker for mac 应用图标 -> Perferences... -> Docker Engine
{
... "registry-mirrors": ["https://02xz0m84.mirror.aliyuncs.com"]
...
}
docker run hello-world
[root@localhost /]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:df5fxxx491a9e
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal. To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
下载地址:https://docs.docker.com/docker-for-mac/install/
如同 macOS 其它软件一样,安装也非常简单,双击下载的 .dmg 文件,然后将图标拖拽到 Application 文件夹即可
从应用中找到 Docker 图标并点击运行。可能会询问 macOS 的登陆密码,输入即可
第一次点击图标,可能会看到这个安装成功的界面,点击 "Got it!" 可以关闭这个窗口
启动终端后,通过命令可以检查安装后的 Docker 版本
docker --version
操作同windows镜像加速一致,之后可以通过 docker info 来查看是否配置成功
$ docker info
... Registry Mirrors:
http://hub-mirror.c.163.com
Live Restore Enabled: false
启动 hello-world 容器
docker run hello-world
[root@localhost /]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:df5f5184104426b65967e016ff2ac0bfcd44ad7899ca3bbcf8e44e4461491a9e
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal. To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
建议使用 Centos7 或者 Centos8 , Centos7 和 Centos8 用法配置都是一样的linux 安装 docker 官方文档: https://docs.docker.com/install/linux/docker-ce/centos/
为了方便测试请关闭 selinux、关闭防火墙
SELinux 防火墙的设置:
[root@localhost ~]# getenforce
Disabled
修改/etc/selinux/config 文件
将 SELINUX=enforcing 改为 SELINUX=disabled
见 【精选】CentOS8防火墙相关命令
1、firewalld 的基本使用: 启动: systemctl start firewalld 关闭: systemctl stop firewalld 查看状态: systemctl status firewalld 开机禁用 : systemctl disable firewalld 开机启用 : systemctl enable firewalld 2、firewall-cmd 的基本使用: 那怎么开启一个端口呢: firewall-cmd --zone=public --add-port=80/tcp --permanent (–permanent 永久生效, 没有此参数重启后失效) 重新载入: firewall-cmd --reload 修改 firewall-cmd 配置后必须重启 查看: firewall-cmd --zone= public --query-port=80/tcp 删除: firewall-cmd --zone= public --remove-port=80/tcp --permanent 查看所有打开的端口: firewall-cmd --zone=public --list-ports
yum install -y yum-utils
yum-config-manager --add-repo
https://download.docker.com/linux/centos/d
ocker-ce.repo
或者阿里云源
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.re
po
yum search docker
yum install docker-ce docker-ce-cli containerd.io -y
systemctl start docker
systemctl enable docker
systemctl status docker
systemctl list-unit-files|grep enabled
systemctl list-unit-files | grep enabled |grep docker
docker info
[root@localhost zph]# docker info
Client:
Context: default
Debug Mode: false
Plugins:
app: Docker App (Docker Inc., v0.9.1-beta3)
buildx: Docker Buildx (Docker Inc., v0.7.1-docker)
scan: Docker Scan (Docker Inc., v0.12.0)
Server:
Containers: 31
Running: 2
Paused: 0
Stopped: 29
Images: 391
Server Version: 20.10.12
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc io.containerd.runc.v2 io.containerd.runtime.v1.linux
Default Runtime: runc
Init Binary: docker-init
containerd version: 7b11cfaabd73bb80907dd23182b9347b4245eb5d
runc version: v1.0.2-0-g52b36a2
init version: de40ad0
Security Options:
seccomp
Profile: default
Kernel Version: 4.18.0-348.el8.x86_64
Operating System: CentOS Linux 8
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 782MiB
Name: localhost.localdomain
ID: DA45:YS5F:4YIO:2ZL3:U4YN:JISO:CWPI:W3A3:OBV3:PGDO:7ZTP:KNPX
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
[root@localhost zph]# docker --version
Docker version 20.10.12, build e91ed57
要安装 特定版本 的 Docker Engine ,请在 repo 中列出可用版本,然后选择并安装: 列出并排序您的存储库中可用的版本,此示例按版本号对结果进行排序,从高到低, 并被截断
yum list docker-ce --showduplicates | sort -r
sudo yum install docker-ce- docker-ce-cli- containerd.i
o
当需要对 docker 服务进行调整配置时,不用去修改主文件 docker.service 的参数,通过daemon.json 配置文件来管理,更为安全、合理
mkdir -p /etc/docker
vi /etc/docker/daemon.json
{
"registry-mirrors": ["https://02xz0m84.mirror.aliyuncs.com"]
}
如果没有/etc/docker 这个目录就创建这个目录,然后重新加载 daemon 重启 docker
systemctl daemon-reload
systemctl restart docker
docker info
启动 hello-world 容器
[root@localhost docker]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
719385e32844: Pull complete
Digest: sha256:88ec0acaa3ec199d3b7eaf73588f4518c25f9d34f58ce9a0df68429c5af48e8d
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
$ sudo yum remove docker-ce docker-ce-cli containerd.io
主机上的映像、容器、卷或自定义配置文件不会自动删除,使用命令删除
$ sudo rm -rf /var/lib/docker
$ sudo rm -rf /var/lib/containerd
必须手动删除任何已编辑的配置文件
访问 https://www.aliyun.com/ 搜索 “容器镜像服务”
[下一节][Docker]二.Docker 镜像,仓库,容器介绍以及详解