19
19

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.

figを使ってDockerのクラスタを作り出す

Posted at

複数のDockerコンテナを起動し、アプリケーションを動作させたりスケーリングを実現する場合にコンテナ間のリンクやスケーリングはFigを利用することでお手軽に実現できます。

fig.yml

figのための設定ファイルはfig.ymlに記述をします。yml形式なので新しいDSLを覚えたりすることがなく、シンプルに必要な事を記述できるようです。今回はよくある「フロントのnginxでリバースプロキシをして、バックエンドのアプリケーションにアクセスを振り分け」のパターンをやってみます。

 ap1:
  image: localhost:5000/application/run # localhostに立てたinsecureなregistryからimageをpullする
  volumes:
    - /usr/local/etc/application/app.httpd.conf:/etc/httpd/conf/httpd.conf:ro
    - /usr/local/etc/application/app.config.ini:/var/www/application/common/config/config.ini:ro
 ap2:
  image: localhost:5000/application/run
  volumes:
    - /usr/local/etc/application/app.httpd.conf:/etc/httpd/conf/httpd.conf:ro
    - /usr/local/etc/application/app.config.ini:/var/www/application/common/config/config.ini:ro
 ap3:
  image: localhost:5000/application/run
  volumes:
    - /usr/local/etc/application/app.httpd.conf:/etc/httpd/conf/httpd.conf:ro
    - /usr/local/etc/application/app.config.ini:/var/www/application/common/config/config.ini:ro
 ap4:
  image: localhost:5000/application/run
  volumes:
    - /usr/local/etc/application/app.httpd.conf:/etc/httpd/conf/httpd.conf:ro
    - /usr/local/etc/application/app.config.ini:/var/www/application/common/config/config.ini:ro
 ap5:
  image: localhost:5000/application/run
  volumes:
    - /usr/local/etc/application/app.httpd.conf:/etc/httpd/conf/httpd.conf:ro
    - /usr/local/etc/application/app.config.ini:/var/www/application/common/config/config.ini:ro

nginx:
  image: nginx
  volumes:
    - /usr/local/etc/application/nginx/nginx.conf:/etc/nginx/nginx.conf
    - /usr/local/etc/application/nginx/cond.d:/etc/nginx/conf.d
  links:
    - ap1
    - ap2
    - ap3
    - ap4
    - ap5
  ports:
    - "80:80"

nginxやアプリケーションの設定については割愛。

fig.ymlを保存した場所で

fig up --allow-insecure-ssl # insecureなregistryを使うのでオプションが必要

あふれるお手軽感

むっちゃお手軽。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?