1.准备软件:
docker安装包,下载地址:https://download.docker.com/linux/static/stable/x86_64/
下载需要的版本到本地,上传到服务器上
2.一键安装命令:install-docker.sh
#!/bin/sh usage(){ echo "使用方法: $0 FILE_NAME_DOCKER_CE_TAR_GZ" echo " $0 docker-18.06.3-ce.tgz" echo "Get docker-ce binary from: https://download.docker.com/linux/static/stable/x86_64/" echo "eg: wget https://download.docker.com/linux/static/stable/x86_64/docker-18.06.3-ce.tgz" echo "" } SYSTEMDDIR=/usr/lib/systemd/system SERVICEFILE=docker.service DOCKERDIR=/usr/bin DOCKERBIN=docker SERVICENAME=docker if [ $# -ne 1 ]; then usage exit 1 else FILETARGZ="$1" fi if [ ! -f ${FILETARGZ} ]; then echo "Docker binary tgz files does not exist, please check it" echo "Get docker-ce binary from: https://download.docker.com/linux/static/stable/x86_64/" echo "eg: wget https://download.docker.com/linux/static/stable/x86_64/docker-18.06.3-ce.tgz" exit 1 fi echo "##unzip : tar xvpf ${FILETARGZ}" tar xvpf ${FILETARGZ} echo echo "##binary : ${DOCKERBIN} copy to ${DOCKERDIR}" cp -p ${DOCKERBIN}/* ${DOCKERDIR} >/dev/null 2>&1 which ${DOCKERBIN} echo "##systemd service: ${SERVICEFILE}" echo "##docker.service: create docker systemd file" cat >${SYSTEMDDIR}/${SERVICEFILE} <<EOF [Unit] Description=Docker Application Container Engine Documentation=http://docs.docker.com After=network.target docker.socket [Service] Type=notify EnvironmentFile=-/run/flannel/docker WorkingDirectory=/usr/local/bin ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock 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=on-failure [Install] WantedBy=multi-user.target EOF echo "" systemctl daemon-reload echo "##Service status: ${SERVICENAME}" systemctl status ${SERVICENAME} echo "##Service restart: ${SERVICENAME}" systemctl restart ${SERVICENAME} echo "##Service status: ${SERVICENAME}" systemctl status ${SERVICENAME} echo "##Service enabled: ${SERVICENAME}" systemctl enable ${SERVICENAME} cat >/etc/docker/daemon.json <<EOF { "registry-mirrors": ["http://oest4bnp.mirror.aliyuncs.com/"] } EOF swapoff -a iptables -P FORWARD ACCEPT sysctl --system systemctl daemon-reload systemctl restart docker.service echo "## docker version" docker version
以上文件可以按自己需求进行修改:该文件对应的docker.service文件及daemon.json文件可以修改
3.登录服务器,跳转到压缩包所在文件,创建shell命令文件:
touch install-docker.sh
4.编辑文件:(可以直接用以下命令,vi命令没有文件时会直接创建新文件)
vi install-docker.sh
5.复制上面代码到install-docker.sh,保存退出,给文件赋权限
chmod +x install-docker.sh
6.运行shell命令
./install-docker.sh docker-18.06.1-ce.tgz
7. 运行完成后查看docker版本:
如图显示,则dockers安装成功!