Add steps for rootless Docker
This commit is contained in:
parent
27ae28797f
commit
fd80dfdba4
|
@ -2,5 +2,5 @@
|
||||||
# code: language=ansible
|
# code: language=ansible
|
||||||
---
|
---
|
||||||
docker_rootless: false
|
docker_rootless: false
|
||||||
docker_rootless_user: docker_user
|
docker_rootless_user: rootlessdocker
|
||||||
docker_rootless_user_uid: 1100
|
docker_rootless_user_uid: 1102
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
update_cache: true
|
update_cache: true
|
||||||
|
|
||||||
- name: Install Docker
|
- name: Install Docker
|
||||||
apt:
|
ansible.builtin.apt:
|
||||||
name:
|
name:
|
||||||
- docker-ce
|
- docker-ce
|
||||||
- docker-ce-cli
|
- docker-ce-cli
|
||||||
|
@ -61,11 +61,32 @@
|
||||||
- fuse-overlayfs
|
- fuse-overlayfs
|
||||||
- slirp4netns
|
- slirp4netns
|
||||||
|
|
||||||
|
- name: Create group for Docker socket
|
||||||
|
ansible.builtin.group:
|
||||||
|
name: docker
|
||||||
|
state: present
|
||||||
|
|
||||||
|
- name: Create user for rootless Docker
|
||||||
|
ansible.builtin.user:
|
||||||
|
name: "{{ docker_rootless_user }}"
|
||||||
|
uid: "{{ docker_rootless_user_uid }}"
|
||||||
|
comment: Rootless Docker User
|
||||||
|
groups:
|
||||||
|
- docker
|
||||||
|
state: present
|
||||||
|
|
||||||
- name: Enable lingering for Docker user
|
- name: Enable lingering for Docker user
|
||||||
ansible.builtin.command:
|
ansible.builtin.command:
|
||||||
cmd: loginctl enable-linger {{ docker_rootless_user }}
|
cmd: loginctl enable-linger {{ docker_rootless_user }}
|
||||||
creates: /var/lib/systemd/linger/{{ docker_rootless_user }}
|
creates: /var/lib/systemd/linger/{{ docker_rootless_user }}
|
||||||
|
|
||||||
|
- name: Set DOCKER_HOST environment variable globally
|
||||||
|
ansible.builtin.lineinfile:
|
||||||
|
path: /etc/profile
|
||||||
|
regexp: '^export DOCKER_HOST='
|
||||||
|
line: export DOCKER_HOST=unix:///run/user/{{ docker_rootless_user_uid }}/docker.sock
|
||||||
|
state: present
|
||||||
|
|
||||||
- name: Run rootless Docker setup script
|
- name: Run rootless Docker setup script
|
||||||
ansible.builtin.command:
|
ansible.builtin.command:
|
||||||
cmd: dockerd-rootless-setuptool.sh install
|
cmd: dockerd-rootless-setuptool.sh install
|
||||||
|
@ -73,15 +94,6 @@
|
||||||
become: true
|
become: true
|
||||||
become_user: "{{ docker_rootless_user }}"
|
become_user: "{{ docker_rootless_user }}"
|
||||||
|
|
||||||
- name: Set DOCKER_HOST environment variable
|
|
||||||
ansible.builtin.lineinfile:
|
|
||||||
path: /home/{{ docker_rootless_user }}/.bashrc
|
|
||||||
regexp: '^export DOCKER_HOST='
|
|
||||||
line: export DOCKER_HOST=unix:///run/user/{{ docker_rootless_user_uid }}/docker.sock
|
|
||||||
state: present
|
|
||||||
become: true
|
|
||||||
become_user: "{{ docker_rootless_user }}"
|
|
||||||
|
|
||||||
- name: Make sure rootless Docker is running
|
- name: Make sure rootless Docker is running
|
||||||
ansible.builtin.systemd_service:
|
ansible.builtin.systemd_service:
|
||||||
scope: user
|
scope: user
|
||||||
|
|
Loading…
Reference in a new issue