一、在线安装方式
注意:确保可以连外网:ping www.baidu.com
1、环境说明
我们使用的是 CentOS 7 (64-bit)
目前,CentOS 仅发行版本中的内核支持 Docker。
Docker 运行在 CentOS 7 上,要求系统为64位、系统内核版本为 3.10 以上。
查看自己的内核
uname -r
2、下载环境
yum -y install gcc
yum -y install gcc-c++
3、 卸载旧版本
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
4、安装需要的软件包
yum install -y yum-utils
5、设置镜像仓库 (docker镜像源需要添加,要不然yum下载不到)
#首选官方
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
#备选
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
6、安装docker
yum install docker-ce docker-ce-cli containerd.io
7、启动docker
systemctl start docker
docker images
8、卸载
systemctl stop docker
yum -y remove docker-ce docker-ce-cli containerd.io
rm -rf /var/lib/docker
二、压缩包安装方式
找下面指的那些包都可以
2 解压
tar -zxvf xxxxxxx
3 将解压出来的docker文件复制到 /usr/bin/ 目录下
cp docker/* /usr/bin/
4 在/etc/systemd/system/目录下新增docker.service文件,内容如下,这样可以将docker注册为service服务
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd --selinux-enabled=false --insecure-registry=127.0.0.1
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 processes 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
systemctl start docker
三、docker-compose安装
安装 docker-compose-plugin
yum install docker-compose-plugin
下载docker compose:
#包小,但是版本比较旧
sudo curl -L https://github.com/docker/compose/releases/download/1.16.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
#慢的话可以用这个,有时候下载下来不好用
sudo curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
官方最新推荐方式:(官方地址:Install the Compose plugin)
DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
mkdir -p $DOCKER_CONFIG/cli-plugins
curl -SL https://github.com/docker/compose/releases/download/v2.16.0/docker-compose-linux-x86_64 -o $DOCKER_CONFIG/cli-plugins/docker-compose
sudo chmod +x /usr/local/lib/docker/cli-plugins/docker-compose
docker compose version
授权
sudo chmod +x /usr/local/bin/docker-compose
查看版本
docker-compose --version