首先,上传文件docker-20.10.9.tgz 到/data/docker/下
1、编辑docker.service文件
docker的配置文件
vim /data/docker/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
Environment=PATH=/usr/local/docker:/usr/bin:/usr/sbin
ExecStart=/usr/local/docker/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
】
2、编辑/data/docker/daemon.json文件
用来修改docker容器的存放位置
vim /data/docker/daemon.json
【
{"data-root": "/data/docker/data"}
】
3、编辑docker.yml文件
vim docker.yml
【
---
- hosts: s104
remote_user: root
tasks:
- name: mkdir
file: name=/data/docker state=directory
- name: copy tar
copy: src=/data/docker/docker-20.10.9.tgz dest=/data/docker/
- name: tar
unarchive: src=/data/docker/docker-20.10.9.tgz dest=/usr/local/ copy=no
- name: copy conf
copy: src=/data/docker/docker.service dest=/etc/systemd/system/
- name: edit profile
ineinfile: name=/etc/profile line="export PATH=$PATH:/usr/local/docker"
- name: source profile
shell: source /etc/profile
- name: reload
shell: systemctl daemon-reload
- name: start docker
service: name=docker state=started
- name: copy json
copy: src=/data/docker/daemon.json dest=/etc/docker/
- name: reload2
shell: systemctl daemon-reload
- name: restart docker
service: name=docker state=restarted
】
4、验证
ansible-playbook docker.yml
被控端192.168.59.104 成功安装上docker
标签:systemd,name,二进制,ansible,usr,docker,copy,data From: https://www.cnblogs.com/leihongnu/p/16738178.html