什么是docker
docker好比是一个个容器,程序在运行的时候自己做自己的事情,互不影响
最简单的一个例子,比如说,你在刚开始的一台服务器部署项目,那么部署项目一定要配置mysql等环境是吧!那么现在你要吧这个项目迁移到另一台服务器上,又要重写在另一台服务器上重写配置mysql等环境.可能会出现版本错乱等错误,很麻烦那么现在第一次部署项目的时候,把项目等环境直接放进docker里面,下次你要迁移项目到另一台服务器上,自己把docker镜像上传到docker仓库上,然后再另一台服务器拉取就直接O了,这只是好处之一
详细请查看:https://blog.youkuaiyun.com/javaeEEse/article/details/122109564
查看CentOS版本
CentOS 仅发行版本中的内核支持 docker。docker 运行在 CentOS 7 上,要求系统为64位、系统内核版本为 3.10 以上。docker 运行在 CentOS-6.5 或更高的版本的 CentOS 上,要求系统为64位、系统内核版本为 2.6.32-431 或者更高版本。
[root@localhost ~]# uname -r
3.10.0-1127.el7.x86_64
安装依赖工具
[root@localhost ~]# sudo yum install -y yum-utils device-mapper-persistent-data lvm2
配置yum,添加软件源信息
[root@localhost ~]# sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
更新yum缓存
[root@localhost ~]# sudo yum makecache fast
安装docker(也可以指定某个版本:sudo yum install docker-ce-xxx.xx)
[root@localhost ~]# sudo yum install docker-ce -y
启动docker服务
[root@localhost ~]# sudo systemctl start docker
PS镜像加速,更换国内源:
[root@localhost ~]# vi /etc/docker/daemon.json
粘贴下面这段保存
{
“registry-mirrors”: [
“https://registry.docker-cn.com”,
“http://hub-mirror.c.163.com”,
“https://docker.mirrors.ustc.edu.cn”
]
}
查看是否成功
[root@localhost ~]# docker info
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 1.13.1
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: systemd
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Swarm: inactive
Runtimes: docker-runc runc
Default Runtime: docker-runc
Init Binary: /usr/libexec/docker/docker-init-current
containerd version: (expected: aa8187dbd3b7ad67d8e5e3a15115d3eef43a7ed1)
runc version: 8891bca22c049cd2dcf13ba2438c0bac8d7f3343 (expected: 9df8b306d01f59d3a8029be411de015b7304dd8f)
init version: fec3683b971d9c3ef73f284f176672c44b448662 (expected: 949e6facb77383876aeff8a6944dde66b3089574)
Security Options:
seccomp
WARNING: You're not using the default seccomp profile
Profile: /etc/docker/seccomp.json
Kernel Version: 3.10.0-1127.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
Number of Docker Hooks: 3
CPUs: 4
Total Memory: 3.682 GiB
Name: localhost.localdomain
ID: O2CC:P2T5:GFV2:HGS3:GLUB:LK5Q:Z57H:JTUG:ZAOT:V7QH:R5I3:67TN
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
Registries: docker.io (secure)
查看docker版本
[root@localhost ~]# docker version
Client:
Version: 1.13.1
API version: 1.26
Package version: docker-1.13.1-209.git7d71120.el7.centos.x86_64
Go version: go1.10.3
Git commit: 7d71120/1.13.1
Built: Wed Mar 2 15:25:43 2022
OS/Arch: linux/amd64
Server:
Version: 1.13.1
API version: 1.26 (minimum version 1.12)
Package version: docker-1.13.1-209.git7d71120.el7.centos.x86_64
Go version: go1.10.3
Git commit: 7d71120/1.13.1
Built: Wed Mar 2 15:25:43 2022
OS/Arch: linux/amd64
Experimental: false
总结:下载完docker后,一直启动不成功,尝试各种办法后发现是需要更新linux内核 原文:https://blog.youkuaiyun.com/yimenglin/article/details/105972326
[root@localhost ~]# yum update
查看docker启动状态
[root@localhost ~]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: active (running) since 三 2022-08-03 18:56:04 CST; 13min ago
Docs: http://docs.docker.com
Main PID: 3521 (dockerd-current)
Tasks: 26
CGroup: /system.slice/docker.service
├─3521 /usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=docker-runc --exec-opt nativ...
└─3530 /usr/bin/docker-containerd-current -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m...
8月 03 18:56:02 localhost.localdomain dockerd-current[3521]: time="2022-08-03T18:56:02.961002597+08:00" level=info msg="libcontainerd: new containe...: 3530"
8月 03 18:56:04 localhost.localdomain dockerd-current[3521]: time="2022-08-03T18:56:04.020188520+08:00" level=info msg="Graph migration to content-...econds"
8月 03 18:56:04 localhost.localdomain dockerd-current[3521]: time="2022-08-03T18:56:04.020848509+08:00" level=info msg="Loading containers: start."
8月 03 18:56:04 localhost.localdomain dockerd-current[3521]: time="2022-08-03T18:56:04.033514540+08:00" level=info msg="Firewalld running: true"
8月 03 18:56:04 localhost.localdomain dockerd-current[3521]: time="2022-08-03T18:56:04.163058258+08:00" level=info msg="Default bridge (docker0) is...ddress"
8月 03 18:56:04 localhost.localdomain dockerd-current[3521]: time="2022-08-03T18:56:04.266029466+08:00" level=info msg="Loading containers: done."
8月 03 18:56:04 localhost.localdomain dockerd-current[3521]: time="2022-08-03T18:56:04.300018450+08:00" level=info msg="Daemon has completed initialization"
8月 03 18:56:04 localhost.localdomain dockerd-current[3521]: time="2022-08-03T18:56:04.300048243+08:00" level=info msg="Docker daemon" commit="7d71...=1.13.1
8月 03 18:56:04 localhost.localdomain dockerd-current[3521]: time="2022-08-03T18:56:04.303342220+08:00" level=info msg="API listen on /var/run/docker.sock"
8月 03 18:56:04 localhost.localdomain systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.