이 글에서는 Ansible을 통해 Raspberry Pi에 Docker 설치를 자동화하는 방법을 설명합니다. 직접 제작한 역할을 사용합니다.

필수 조건

Docker 설치

역할 다운로드
이 자동화를 위해 제가 ansible 역할을 개발했습니다. 이를 다운로드하는 방법은 다음과 같습니다:

git clone https://gitlab.com/jls42/ansible-rpi-docker.git roles/ansible-rpi-docker

자세한 내용은 ansible-rpi-docker 문서를 참조하세요.

인벤토리 파일 생성: inventory
이 예제의 인벤토리에서는 Raspberry Pi의 IP가 192.168.1.190입니다.

[rpi1]
192.168.1.190 servername=rpi1

playbook docker-rpi.yml 준비

---
- name: "Installation de Docker sur le Raspberry Pi"
  hosts: rpi1
  remote_user: "pi"
  roles:
    - roles/ansible-rpi-docker
  vars:
    docker_version: 18.06.1~ce~3-0~raspbian

Docker 배포

export ANSIBLE_HOST_KEY_CHECKING=False
ansible-playbook -b -i inventory docker-rpi.yml

다음과 같이 됩니다:

jls42@boo:~/rpi$ ansible-playbook -b -i inventory docker-rpi.yml

PLAY [Installation de Docker sur le Raspberry Pi] ******************************************************************************************************************************************************************************************

TASK [Gathering Facts] *********************************************************************************************************************************************************************************************************************
Sunday 09 December 2018  01:20:47 +0100 (0:00:00.050)       0:00:00.051 *******
ok: [192.168.1.190]

TASK [roles/ansible-rpi-docker : Installe les paquets nécessaires à l'utilisation d'un dépôt HTTPS] *****************************************************************************************************************************************
Sunday 09 December 2018  01:20:50 +0100 (0:00:03.350)       0:00:03.401 *******
changed: [192.168.1.190] => (item=[u'apt-transport-https', u'ca-certificates', u'curl', u'gnupg2', u'software-properties-common'])

TASK [roles/ansible-rpi-docker : Ajoute la clef officielle du dépôt Docker] ****************************************************************************************************************************************************************
Sunday 09 December 2018  01:21:41 +0100 (0:00:51.274)       0:00:54.675 *******
changed: [192.168.1.190]

TASK [roles/ansible-rpi-docker : Ajoute le dépôt Docker] ***********************************************************************************************************************************************************************************
Sunday 09 December 2018  01:21:46 +0100 (0:00:04.766)       0:00:59.442 *******
changed: [192.168.1.190]

TASK [roles/ansible-rpi-docker : Installe le paquet docker-ce] *****************************************************************************************************************************************************************************
Sunday 09 December 2018  01:21:57 +0100 (0:00:10.451)       0:01:09.893 *******
changed: [192.168.1.190]

TASK [roles/ansible-rpi-docker : Installe python-pip] **************************************************************************************************************************************************************************************
Sunday 09 December 2018  01:23:14 +0100 (0:01:17.283)       0:02:27.177 *******
changed: [192.168.1.190]

TASK [roles/ansible-rpi-docker : Installe docker-compose via pip] **************************************************************************************************************************************************************************
Sunday 09 December 2018  01:24:02 +0100 (0:00:48.630)       0:03:15.807 *******
changed: [192.168.1.190]

TASK [roles/ansible-rpi-docker : Configure Docker pour qu'il démarre au boot] **************************************************************************************************************************************************************
Sunday 09 December 2018  01:24:58 +0100 (0:00:55.582)       0:04:11.390 *******
ok: [192.168.1.190]

TASK [roles/ansible-rpi-docker : Ajoute l'utilisateur pi dans le groupe docker] ************************************************************************************************************************************************************
Sunday 09 December 2018  01:24:59 +0100 (0:00:01.089)       0:04:12.480 *******
changed: [192.168.1.190]

TASK [roles/ansible-rpi-docker : Supprime la swap] *****************************************************************************************************************************************************************************************
Sunday 09 December 2018  01:25:00 +0100 (0:00:01.265)       0:04:13.745 *******
changed: [192.168.1.190]

PLAY RECAP *********************************************************************************************************************************************************************************************************************************
192.168.1.190              : ok=10   changed=8    unreachable=0    failed=0   

Sunday 09 December 2018  01:25:02 +0100 (0:00:02.002)       0:04:15.748 *******
===============================================================================
roles/ansible-rpi-docker ---------------------------------------------- 252.35s
setup ------------------------------------------------------------------- 3.35s
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
total ----------------------------------------------------------------- 255.70s
Playbook run took 0 days, 0 hours, 4 minutes, 15 seconds
jls42@boo:~/rpi$

확인

Docker가 제대로 설치되었는지 확인하기 위해 Raspberry Pi에 접속합니다.

jls42@boo:~/rpi$ ssh pi@192.168.1.190
Linux rpi1 4.14.79-v7+ #1159 SMP Sun Nov 4 17:50:20 GMT 2018 armv7l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sun Dec  9 00:25:01 2018 from 192.168.1.42
pi@rpi1:~ $ docker --version
Docker version 18.06.1-ce, build e68fc7a

즐기세요!

이 문서는 gpt-4o 모델을 사용하여 fr 버전에서 ko 언어로 번역되었습니다. 번역 과정에 대한 자세한 정보는 https://gitlab.com/jls42/ai-powered-markdown-translator를 참조하십시오.