docker-compose.yaml:
nginx:
image: nginx
links:
- tomcat
- ghost
ports:
- "80:80"
volumes:
- /root/conf:/etc/nginx/conf.d:ro
tomcat:
image: tomcat:8.5
links:
- mysql
volumes:
- /root/tomcat-users.xml:/usr/local/tomcat/conf/tomcat-users.xml
- /root/manager.xml:/usr/local/tomcat/conf/Catalina/localhost/manager.xml
mysql:
image: mysql
volumes:
- /opt/data:/var/lib/mysql
- /root/xx.sql:/docker-entrypoint-initdb.d/xx.sql
environment:
- MYSQL_ROOT_PASSWORD=xxxx
ghost:
image: ghost
volumes:
- /root/blog:/var/lib/ghost
environment:
- NODE_ENV=production
注意tomcat的manager
默认只有本机能访问,如果需要非本机访问的,需要配置manager.xml
,不然访问tomcat控制台会报403,位置在:$CATALINA_BASE/conf/[enginename]/[hostname]
,内容如下:
<Context privileged="true">
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow=".*"/>
</Context>
启动docker container:
docker-compose up -d
java代码中连接数据库,字符串写法为:
url=jdbc:mysql://${MYSQL_PORT_3306_TCP_ADDR}:3306/codepad?useUnicode=true&characterEncoding=UTF-8
MYSQL_PORT_3306_TCP_ADDR是mysql container的ip地址,由mysql docker container生成,intellij idea 本地运行时得在run/debug窗口事先配置好.
参考文档见: