4
4

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.

vagrant の中の docker サービスに(vagrant の)ホストから docker-fabric で接続してイメージをビルドする

Last updated at Posted at 2015-12-21

はじめに

docker-fabric は、名前の通り、 fabric で対象サーバーに操作を行う時に、 docker のコマンドをいろいろ使えるようにする python パッケージです。 Docker-Map (そして docker-py ) を拡張して定義されている形になっています。

インストール

docker-fabric のインストールは、 pip を使って行いました。

sudo pip install docker-fabric

ファイル用意

fabfile.py
from fabric.api import run
from fabric.api import env
from fabric.api import task
from dockerfabric import tasks as docker
from dockermap.api import DockerFile
from dockerfabric.apiclient import docker_fabric

env.docker_tunnel_local_port = 22024
env.docker_api_version = "1.20"

@task
def my_task():
    dockerfile = DockerFile('ubuntu', maintainer='ME, me@example.com')
    dockerfile.run('echo hello wolrd > /hello-world.txt')
    docker_fabric().build_from_file(dockerfile, 'hoge_img')

実行

fab -H vagrant@127.0.0.1:2222 my_task を実行すると、 vagrant のパスワードを聞かれるので、 vagrant を入力。hoge_img イメージが、 vagrant 内の docker イメージとしてビルドされる。

4
4
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
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?