add docker service configuration options

This commit is contained in:
afreisinger 2025-05-29 23:41:25 -03:00
parent 94b787389d
commit 0c95311e70
4 changed files with 31 additions and 0 deletions

View File

@ -131,6 +131,15 @@ docker_daemon_options:
Custom `dockerd` options can be configured through this dictionary representing the json file `/etc/docker/daemon.json`.
```yaml
docker_service_settings:
- HTTP_PROXY=http://proxy.example.com:80
- HTTPS_PROXY=https://proxy.example.com:443
- NO_PROXY=localhost,127.0.0.1,docker-registry.example.com,.corp
```
Custom docker service configuration. Should only be used for `HTTP/HTTPS proxy` settings.
## Use with Ansible (and `docker` Python library)
Many users of this role wish to also use Ansible to then _build_ Docker images and manage Docker containers on the server where Docker is installed. In this case, you can easily add in the `docker` Python library using the `geerlingguy.pip` role:

View File

@ -66,3 +66,6 @@ docker_users: []
# Docker daemon options as a dict
docker_daemon_options: {}
# Docker HTTP/HTTPS proxy settings as list of environment configurations
docker_service_settings: []

View File

@ -65,6 +65,21 @@
when: docker_daemon_options.keys() | length > 0
notify: restart docker
- name: Create docker config target directory
file:
path: /etc/systemd/system/docker.service.d
state: directory
mode: 0755
when: docker_service_settings | length > 0
- name: Configure docker service environment.
template:
src: http-proxy.conf.j2
dest: /etc/systemd/system/docker.service.d/http-proxy.conf
mode: 0644
when: docker_service_settings | length > 0
notify: restart docker
- name: Ensure Docker is started and enabled at boot.
service:
name: docker

View File

@ -0,0 +1,4 @@
[Service]
{% for docker_service_setting in docker_service_settings %}
Environment="{{ docker_service_setting }}"
{% endfor %}