目录
核心概念
-
镜像
- 类似虚拟机镜像、模板
- 类似JAVA类
- 是创建容器的基础
-
容器
- 轻量级沙箱
- 利用容器运行和隔离
- 可理解为被实例化的类
- 简易版Linux系统环境
- 用户权限
- 进程空间
- 用户空间
- 网络空间
- 时区
- IPC
- 等等
-
仓库
- 代码仓库
- 存放镜像的场所
- 分类
- 公开仓库
- Docker Hub
- 阿里云
- 腾讯云
- 私有仓库
- 公开仓库
安装Docker引擎
下载
http://www.docker.com/get-docker
引擎分类
- 社区版本(CE)
- Community Edition
- 包含大部分核心功能
- 每月发布尝鲜(Edge)版本
- 每季度(3、6、9、12)发布稳定(Stable)版本
- 版本号命名"年份.月份" v18.06
- 企业版本(EE)
- Enterprise Edition
- 认证支持
- 镜像管理
- 容器托管
- 安全扫描
Ubuntu环境安装
CentOS环境安装
Yum安装
yum install -y docker-ce docker-io container systemctl start docker
如果是CentOS8,需要修改firewalld配置。
CentOS8默认使用firewalld,而Docker使用iptables实现转发。
vi etc/firewalld/firewalld.conf
找到如下配置
# FirewallBackend
# Selects the firewall backend implementation.
# Choices are:
# - nftables (default)
# - iptables (iptables, ip6tables, ebtables and ipset)
FirewallBackend=iptables
将默认值的nftables改为iptables
脚本安装
wget -qO- https://get.docker.con/sh
Mac环境安装
Windows环境安装
配置Docker服务
用户组配置
sudo usermod -aG docker USER_NAME
将用户添加到Docker组中,避免频繁切换特权身份
服务启动
Docker启动是调用了dockerd命令,支持多种参数。
例:使用Debug模式启动,并监听本地2376端口
dockerd -D -H tcp://127.0.0.1:2376
该选项也可写入 /etc/docker/daemon.json 配置文件,由dockered服务启动时读取
{ "debug":true, "hosts":["tcp://127.0.0.1:2376"] }
Ubuntu的Docker
Ubuntu使用Upstart管理启动服务
默认配置文件为
/etc/default/docker
CentOS/RedHat的Docker
使用systemd管理
配置文件路径
/etc/systemd/system/docker.service.d/docker.conf
修改后需要重启
systemctl daemon-reload systemctl start docker.service
Docker日志
/var/log/messages #或 journalctl -u docker.service
启动状态确认
可通过docker info查看
[root@VCentOS8-181 ~]# docker info
Client:
Debug Mode: false
Server:
Containers: 13
Running: 12
Paused: 0
Stopped: 1
Images: 5
Server Version: 19.03.13
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
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
Default Runtime: runc
Init Binary: docker-init
containerd version: 8fba4e9a7d01810a393d5d25a3621dc101981175
runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
init version: fec3683
Security Options:
seccomp
Profile: default
Kernel Version: 4.18.0-193.28.1.el8_2.x86_64
Operating System: CentOS Linux 8 (Core)
OSType: linux
Architecture: x86_64
CPUs: 8
Total Memory: 31.23GiB
Name: VCentOS8-181
ID: B73E:EEKA:CT4F:WGLE:AFWR:LW3R:OLEG:4BMB:67MS:3QUR:HBI3:HR2P
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
Registry Mirrors:
https://hub-mirror.c.163.com/
https://mirror.baidubce.com/
Live Restore Enabled: false