##前提条件
- CentOS7 on Vagrant (IP:192.168.33.10)
- docker-compose version:1.13.1:
- docker version: 1.10.2
##まずはnginx単独で
./nginx/Dockerfile
#公式イメージでも良いが変更を考慮してDockerfileにて実施
FROM nginx:1.11
./nginx/conf.d/nginx.conf
# Configuration for the server
server {
listen 8080;
server_name localhost;
root /usr/share/nginx/html;
location / {
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ /\.ht {
deny all;
}
}
docker-compose.yml
version: '2'
services:
nginx:
build: nginx/
hostname: ng01
ports:
- 8080:8080
volumes:
- ./nginx/conf.d:/etc/nginx/conf.d
- ./nginx/log:/var/log/nginx
container_name: nginx01
これでとりあえず起動すると
docker-compose up -d
http://192.168.33.10:8080/
にてnginxのhomeへアクセス可能
nginx with tomcat
###Dockerfile
./tomcat/Dockerfile
FROM tomcat:8.5
tomcat(app) は8090ポートで連携する。
今のversionではlinksの定義は不要. nginx01 container からping app/app01が可能
docker-compose.yml
version: '2'
services:
nginx:
build: nginx/
hostname: ng01
ports:
- 8080:8080
volumes:
- ./nginx/conf.d:/etc/nginx/conf.d
- ./nginx/log:/var/log/nginx
container_name: nginx01
app:
build: tomcat/
hostname: appserver
ports:
- 8090:8090
volumes:
- ./tomcat/conf:/usr/local/tomcat/conf
- ./tomcat/log:/usr/local/tomcat/log
container_name: app01
###nginxのconfに修正を加える。
./nginx/conf.d/nginx.conf
# Configuration for the server
....
location / {
#以下の1行追加(container_nameのapp01でもOK)
proxy_pass http://app:8090;
index index.html index.htm;
}
....
}
tomcat のserver.xml のポートも8080->8090に修正
./tomcat/conf/server.xml
....
<Connector port="8090" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
http://192.168.33.10:8080/
にアクセスしてみると今度はtomcat homeが見えるはず。