GithubHelp home page GithubHelp logo

hogehoge-banana / sample-docker-deploy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from togana/sample-docker-deploy

1.0 2.0 0.0 6 KB

dockerを使ったデプロイ方法のサンプル

License: MIT License

HTML 5.26% Shell 94.74%

sample-docker-deploy's Introduction

SAMPLE-DOCKER-DEPLOY

概要

docker1.12から追加された docker swarm mode とdocker1.13から追加された docker stack deploy を用いてダウンタイムのないデプロイ方法のサンプル

動作確認したバージョン情報

  • macOS Sierra 10.12.2
  • docker 1.13.0
  • docker-machine 0.9.0
  • docker-compose 1.10.0

構成

現在使用している構成は

local(ブラウザ) -> nginx(プロキシ) -> nginx(コンテナ) -> app(コンテナ) -> バックエンドAPI

上記のnginx(コンテナ)のところにngx_dynamic_upstreamを使用してデプロイ時にapp(コンテナ)の数を倍にしてcurlを叩いてアップストリームに追加して古い方を削除するという方法を取っていました。 nginxがコンテナで実行している理由はapp(コンテナ)はportをホストに繋がず docker network ないのみでアクセスできるようにして複数のコンテナを実行できるようにするためでした。

今回検討している構成は

local(ブラウザ) -> nginx(プロキシ) -> app(コンテナ) -> バックエンドAPI

となる予定です。今までnginx(コンテナ)にまかせていた docker network のロードバランシングを docker swarm mode のロードバランサー(オーバーレイネットワーク)に任せることにします。 そしてデプロイ時に docker ps -q -f name=app | xargs docker inspect --format="{{ index .Config.Labels \"com.docker.compose.container-number\" }}{{\":\"}}{{ index .ID }}{{\":\"}}{{with index .NetworkSettings.Networks \"front-tier\" }}{{ .IPAddress }}{{end}}" のような感じの丹精込めて作られたコマンドを捨てるために docker stack deploy を取り入れられないかと考えました。

sampleなので実際に試す環境は下記になります。 間に挟んだりappコンテナからアクセスするだけなので今回は外しています。

local(ブラウザ) -> app(コンテナ)

ディレクトリ構成

├── README.md          (このファイル)
├── nginx-app          (appのイメージ←ここは別のリポジトリを作成して管理すべきですがサンプルなのでまとめました)
├── registry           (swarmを使う場合dockrehub or registryが必須なので非公開環境を用意)
└── sh                 (実行シェル)

docker-registry+swarmサーバの準備

$ ./sh/init.sh

appのビルド

# args
#  - docker-registryのアクセスポイント(defalt: localhost)
#  - tag名(defalt: latest)
$ ./sh/build.sh $(docker-machine ip container-registry):5000 latest

デプロイ

# args
#  - docker-registryのアクセスポイント(defalt: localhost)
#  - tag名(defalt: latest)
$ ./sh/deploy.sh $(docker-machine ip container-registry):5000 latest

確認

$ curl http://$(docker-machine ip sample-docker-deploy)

片付け

$ ./sh/delete.sh

sample-docker-deploy's People

Contributors

togana avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.