在Docker中使用jboss或tomcat服务器运行java应用程序
我已经在我的Windows机器上安装docker,并按照“ https://registry.hub.docker.com/u/dockerfile/java/ ”中的说明运行Java安装映像,它允许我按预期运行java命令。 但是可以说我有一个Java应用程序需要在Jboss或者tomcat上运行。 如何为此创build映像以及如何添加我的应用程序war文件以在服务器中进行部署。 因为我没有太多关于创builddocker文件的知识。 如果你能告诉我如何完成这个任务,这将会非常有帮助,所以我可以使用docker在Jboss / tomcat服务器上运行我的应用程序。
像这样创build一个Dockerfile:
FROM dockerfile/java # Install Tomcat RUN sudo apt-get update && sudo apt-get install tomcat7 # Add your webapp file into your docker image into Tomcat's webapps directory # Your webapp file must be at the same location as your Dockerfile ADD mywebapp.war /var/lib/tomcat7/webapps/ # Expose TCP port 8080 EXPOSE 8080 # Start Tomcat server # The last line (the CMD command) is used to make a fake always-running # command (the tail command); thus, the Docker container will keep running. CMD sudo service tomcat7 start && tail -f /var/log/tomcat7/catalina.out
build立图像:
$ docker build -t tomcat7-test <Dockerfile's path>
然后,运行它:
$ docker run -d -p 8080:8080 tomcat7-test
运行这个:
sudo apt-get -y install tomcat7
确保在install
之前添加-y
。