5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Docker for Macで、AnsibleからDocker コンテナを作成する

5
Last updated at Posted at 2016-10-05

早速サンプル

  • hosts
[docker_host]
docker_host01
  • sample1.yml
 - hosts: docker_host
   connection: local 

  tasks:
  - name: Create container
    docker: image=centos:centos6 name=web01 ports=80:80 expose=80 tty=yes
  • 実行
$ ansible-playbook -i hosts.yml sample2.yml

結果

$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                NAMES
c9af58da34d9        centos:centos6      "/bin/bash"         13 seconds ago      Up 11 seconds       0.0.0.0:80->80/tcp   web01

指定したコンテナが作成されている事が確認できました。
手法は、PlayBook中にconnection: localと記載する事です。
connection: localとする事で、AnsibleはLoclhostに接続しDockerコマンドを発行しています。

こちらと組み合わせる事で、
コンテナの作成→コンテナのプロビジョニングと一連の動作がAnsibleから行えると思います。

5
3
0

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
5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?