LoginSignup
10

More than 5 years have passed since last update.

AnsibleによるDocker Engineのインストール(Ubuntu 16.04 LTS)

Last updated at Posted at 2017-02-01

Docker公式のUbuntuでのDockerインストール手順
Ansibleで自動化して、Playbook配布可能な状態にしておこうと思います。

※2017/03/25 追記
dockerが17にバージョンアップしたので、修正版を追加します。
商用版のEEは利用していないので、コミュニティ版のCEのインストール方法のみです。

事前準備

事前準備として、Ansibleのインストール手順

apt-get update
apt-get install -y software-properties-common
apt-add-repository ppa:ansible/ansible
apt-get install -y ansible

Dockerのインストール(docker 17.03.0-ce で検証済み)

playbook.yml
# hostsなどの記述については省略します。
- name: Check kernel version.
  fail: msg="Kernel {{ ansible_kernel }} is not supported."
  when: "ansible_kernel | version_compare('3.10', '<')"

- name: apt-get install packages
  apt: pkg={{ item }} state=present update_cache=yes
  with_items:
    - apt-transport-https
    - ca-certificates
    - curl
    - linux-image-extra-virtual
    - linux-image-extra-{{ ansible_kernel }}
    - software-properties-common

- name: Check docker gpg key.
  shell: apt-key fingerprint 0EBFCD88 | grep 0EBFCD88
  register: docker_gpg
  ignore_errors: True
  changed_when: False

- name: Add Docker’s official GPG key
  shell: curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  when: docker_gpg | failed

- name: define lsb_release -cs
  shell: lsb_release -cs
  ignore_errors: True
  register: lsb_release

- name: set up the stable repository
  shell: add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ lsb_release.stdout }} stable"

- name: Install docker-ce.
  apt: name=docker-ce state=present update_cache=yes
  notify:
    - restart docker

Dockerのインストール(docker version 17以前)

playbook.yml
# hostsなどの記述については省略します。
- name: Check kernel version.
  fail: msg="Kernel {{ ansible_kernel }} is not supported."
  when: "ansible_kernel | version_compare('3.10', '<')"

- name: apt-get install packages
  apt: pkg={{ item }} state=present update_cache=yes
  with_items:
    - curl
    - linux-image-extra-{{ ansible_kernel }}
    - linux-image-extra-virtual
    - apt-transport-https
    - ca-certificates

- name: Check docker gpg key.
  shell: apt-key list | grep 2C52609D
  register: docker_gpg
  ignore_errors: True
  changed_when: False

- name: Add Docker’s official GPG key
  shell: curl -fsSL https://yum.dockerproject.org/gpg | sudo apt-key add -
  when: docker_gpg | failed

- name: define lsb_release -cs
  shell: lsb_release -cs
  ignore_errors: True
  register: lsb_release

- name: set up the stable repository
  shell: add-apt-repository "deb https://apt.dockerproject.org/repo/ ubuntu-{{ lsb_release.stdout }} main"

- name: Install docker-engine.
  apt: name=docker-engine state=present update_cache=yes
  notify:
    - restart docker

あとはdocker version などでインストールされていることを確認してみてください。

誤記についてのご指摘や、よりよい方法のご提案などは歓迎します!
以上です。お疲れ様でしたー。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10