Docker安装
-
下载 docker 国内镜像链接(博主下载的是docker-18.06.3-ce.tgz版本)
-
解压下载的docker包
tar zxvf docker-18.06.3-ce.tgz
-
复制解压出来的docker到/usr/bin/目录下
sudo cp docker/* /usr/bin/
-
在以下目录下新建一个文件 docker.service
vim /etc/systemd/system/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
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
如果需要修改镜像默认保存位置,将上面代码中的 ExecStart=/usr/bin/dockerd
改为 ExecStart=/usr/bin/dockerd --graph= /data/docker
即修改了新的镜像保存位置为 /data/docker
。(如果想查看是否修改成功了,可以重新启动docker后用docker info
命令查看)
5. systemctl daemon-reload 加载文件 使其生效
6. 运行 systemctl restart docker 重启动docker
7. systemctl enable docker 开机自启docker命令
docker-compose安装
其安装非常简单,下一个对应版本的docker-compose文件,移动到对应位置,然后修改其名字为docker-compose,增加执行权限之后就可以直接使用docker-compose了
具体操作步骤
- 直接在线安装
curl -L https://get.daocloud.io/docker/compose/releases/download/1.29.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
- 离线安装
- 从git上下载对应版本的docker-compose文件链接
- 移动位置并修改名字
mv docker-compose-Linux-x86_64 /usr/local/bin/docker-compose
- 修改权限
chmod +x /usr/local/bin/docker-compose