5
7

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でnginx + apache2 + wildflyの環境構築手順

Last updated at Posted at 2015-10-10

概要

以前、ubuntuにnginx + apache2 + wildflyの環境構築手順を書いたが、あまりに面倒なので色々調べてたらdockerでインストールできることがわかったのでやってみる手順。

構成

./
|- wildfly-app/
|  |- Dockerfile
|  `- wildfly-app.war
|
|- nginx/
|  |- Dockerfile
|  `- wildfly-app.local.conf
`- apache2/

dockerのインストール

割愛

wildfly-appの設定と起動

Dockerfileは以下。

wildfly-app/Dockerfile
# jboss/wildflyをインストール
FROM jboss/wildfly

# アプリケーションファイルを追加
ADD wildfly-app.war /opt/jboss/wildfly/standalone/deployments/

以下が実行するコマンド。

## 移動
$ cd wildfly-app

## build. イメージ名は sat8bit/wildfly-app
$ docker build -t sat8bit/wildfly-app

## run. コンテナ名は wildfly-app.local
$ docker run -d -it --name wildfly-app.local sat8bit/wildfly-app

ここまでで、wildfly-app.local という名前がついた docker の container で wildfly が立ち上がった。

nginxの設定と起動

nginx/wildfly-app.local.conf
server {
    # master.application.domainへのアクセスの設定
    server_name master.application.domain;
    location / {
        # アプリケーションを起動したdockerで設定したnameをホスト名に設定する
        proxy_pass http://wildfly-app.local:8080/;
    }
}
nginx/Dockerfile
# nginxをインストール
FROM nginx

# 設定ファイルを追加
ADD wildfly-app.local.conf /etc/nginx/conf.d/

以下が実行するコマンド。

## 移動
$ cd nginx

## build. イメージ名は sat8bit/nginx
$ docker build -t sat8bit/nginx

## run.
### --link で同じdocker上で動いている別のコンテナに紐付ける
### -p でホストOSの80番ポートをこのcontainerの80番に繋ぐ
$ docker run -d -it --link wildfly-app.local:wildfly-app.local -p 80:80 sat8bit/nginx

これで、ホストOSの80番からnginxの80番ポートに繋がり、nginxの設定でwildfly-app.localの8080にproxyされる構成ができた。

apache2

apache2のコンテナ作って、それ用のnginxのconfファイルを追加してあげればapache2の方もできそう。

その他

dockerの操作を適当にメモする。

# 動いているコンテナを知りたい場合は
docker ps

# 動いてないコンテナも含める場合は
docker ps -a

# イメージを見る場合は
docker images

# 名前がついていないイメージも全部見る場合は
docker images -a

# 動いているコンテナを止める場合は docker psからコンテナIDを取得して
docker stop <CONTAINER_ID>

# コンテナを削除するには、コンテナを止めたあとに
docker rm <CONTAINER_ID>

# イメージを削除する場合は、docker imagesからイメージIDを取得して
docker rmi <IMAGE_ID>
5
7
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
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?