简介

  Docker是一个开源的应用容器引擎,可以将一整套环境打包成镜像,不需要重复配置环境.可以将每个Docker理解为盒子,在盒子中装任何想要的东西.而每个盒子之间不会互相影响,各司其职.

  当一台服务器上有多个docker环境(nginx+php或apache+php),它们之间是不会相互影响的.例如当nginx环境的站点访问量剧增,CPU上升导致卡顿,那同一台服务器下的apache环境也会收到影响.而Docker进程隔离互不影响.

  使用Docker启动速度快,保证了环境的一致性.解决了环境问题,例如很常见的在自己的开发环境运行的好好的,当上线到测试环境或者正式环境就出现错误的问题.

Docker安装

# 设置仓库所需包
[root@docker ~]# yum install -y yum-utils device-mapper-persistent-data lvm2

# 设置仓库
[root@docker ~]# sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

# 设置源
[root@docker ~]# sudo yum install -y docker-ce docker-ce-cli containerd.io


# 查看版本
[root@docker ~]# docker version
# 输出信息.出现客户端版本,不能连接daemon的信息(原因没启动docker)
Client:
 Version:         1.13.1
 API version:     1.26
 Package version:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
# 开启docker服务
service docker start
# 查看docker版本
docker version
# 输出信息
Client: Docker Engine - Community
 Version:           20.10.14
 API version:       1.41
 Go version:        go1.16.15
 Git commit:        a224086
 Built:             Thu Mar 24 01:49:57 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.14
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.15
  Git commit:       87a90dc
  Built:            Thu Mar 24 01:48:24 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.5.11
  GitCommit:        3df54a852345ae127d1fa3092b95168e4a88e2f8
 runc:
  Version:          1.0.3
  GitCommit:        v1.0.3-0-gf46b6ba
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

安装docker应用程序

# 搜索docker
brew search docker
# 安装docker应用程序
brew cask install docker

启动Docker应用程序,在状态栏出现登录界面,登录即可启动
image-20200314004905548.png
登录成功后Docker状态栏为启动中
2020-03-13T22:45:43.png
验证

# 输出docker
docker version
# 输出信息
Client: Docker Engine - Community
 Version:           19.03.8
 API version:       1.40
 Go version:        go1.12.17
 Git commit:        afacb8b
 Built:             Wed Mar 11 01:21:11 2020
 OS/Arch:           darwin/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.8
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.17
  Git commit:       afacb8b
  Built:            Wed Mar 11 01:29:16 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.2.13
  GitCommit:        7ad184331fa3e55e52b890ea95e65ba581ae3429
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

Docker镜像

# vi /etc/docker/daemon.json 没有创建该文件
{"registry-mirrors":["https://hub-mirror.c.163.com","https://registry.docker-cn.com"]}
# 重启
service docker restart
# 查看镜像信息
docker info
# 注册镜像部分信息
Registry Mirrors:
 https://hub-mirror.c.163.com
 https://registry.docker-cn.com


点击状态栏Docker->Preferences->Docker Engine
image-20200314010024470.png
修改镜像地址

{
  "experimental": false,
  "debug": true,
  "registry-mirrors": [
     "https://hub-mirror.c.163.com",
     "https://registry.docker-cn.com"
  ]
}

image-20200314011427993.png
验证

docker info
# 注册镜像部分信息
Registry Mirrors:
  https://hub-mirror.c.163.com/
  https://registry.docker-cn.com/

Last modification:March 28th, 2022 at 10:58 am