当前系统版本:CentOS Linux release 7.9.2009 (Core)
内核版本:3.10.0-1160.el7.x86_64
注:系统内核版本要求3.10以上
uname -r #查看当前系统内核版本
cat /etc/redhat-release # 查看当前系统版本
yum update (非正式环境下使用)
版本介绍docker-ce社区版 docker-ee企业版 docker-ce-cli客户端 containerd.io 容器
官网下载地址(https://download.docker.com/linux/static/stable/x86_64/docker-19.03.10.tgz)
我这里已docker-19.03.10.tgz该版本做演示
pwd
/usr/loca/src/ ##自定义文件目录用来存放docker的源码包
tar -zxvf docker-19.03.10.tgz #解压文件
cp docker/* /usr/bin/ #复制解压后文件到/bin(必做)
vi /etc/systemd/system/docker.service
添加如下内容
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewall.service
Wants=network-online.target
[Service]
Type=notify
#the default is not to use systemd for cgroups because the delegay issues still
#exists and systemd currently does not support the cgroup feature set required
#for containers run by docker
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
#Having non-zero Limit*s causes performance problems due to accounting overhead
#in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
#Uncomment TasksMax if your systemd version supports it.
#Only Systemd 226 and above support this version
#TasksMax=infinity
TimeoutStartSec=0
#set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
#kill only the docker process, not all process in the cgroup
KillMode=process
#restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
chmod +x /etc/systemd/system/docker.service
systemctl daemon-reload #重新加载配置(每次修改文件后需执行)
systemctl start docker.service
systemctl status docker.service
systemctl enable docker.service ##使服务开启自启
注:如遇到启动不成功可通过状态查询、/var/log/messages/运行日志或直接使用dockerd命令查看错误信息,如还解决不了建议服务器重启一下在运行docker 启动命令
vi /etc/docker/daemon.json
{
"registry-mirrors": ["https://registry.docker-cn.com"]
}
systemctl daemon-reload #重新加载配置(每次修改文件后需执行)
systemctl restart docker.service
docker version ##或
docker -v
注:使用 docker pull 拉取镜像的时候需要网络,但是项目部署一般都是在内网。内网访问不了外网,所以需要在外 网环境下把需要的镜像拉取下来打包,然后拷贝到内网,载入到内网的docker
docker pull mysql ##拉取mysql 镜像mysql后不跟版本号默认为最新版本
docker images ## 查看镜像
docker save -o mysql.tar mysql:latest
docker save #容器ID or name 导出镜像
docker load -i mysql.tar ##导入镜像
docker images
docker pull [IMAGE_NAME]:[TAG] #命令格式
docker pull mysql:8.0 #下载mysql8.0镜像(不指定默认下载最新版本)
docker -v #查看当前安装版本
docker version #查看版本信息
docker info #查看系统信息
docker images #查看当前镜像
docker search 镜像名 #搜索镜像
docker rm 容器ID
docker rm 容器名字
docker rmi 镜像ID
docker rmi 镜像名
docker rmi -f 镜像ID #强制删除
docker volume create +数据卷名称
docker volume list #查看当前数据卷信息
docker network create -d bridge +网络名称
docker network ls #查看当前网络
docker inspect containername +id # 查看容器的hash值
docker stop $(docker ps -a | awk ‘{ print $1}‘ | tail -n +2) #关闭所有容器
docker start $(docker ps -a | awk ‘{ print $1}‘ | tail -n +2) #开启所有容器
docker inspect 容器ID (使用该命令重点关注容器ip) ##查看容器/镜像元数据
docker exec ##在运行的容器中执行命令
docker exec -it 容器ID /bin/bash ##以交互模式开启伪终端
原文:https://www.cnblogs.com/sccq-1/p/15181500.html