Home  >  Q&A  >  body text

网站部署 - 关于使用docker搭建SpringMVC项目的疑问。

大家好,有人使用docker部署过java的web项目没有。

小弟有一些疑问,我现在所知道的:我能使用DaoCloud或者是时速云来搭建一个运行有tomcat的主机,也可以搭建一个运行有mysql的主机,但是我不清楚的是,我该如何才能在同一个主机中部署上mysql和tomcat(是需要我自己来编写dockerfile吗?),并设置mysql的密码,我想跑的是一个java的网站项目。

提前谢过啦。

巴扎黑巴扎黑2709 days ago814

reply all(2)I'll reply

  • 黄舟

    黄舟2017-04-22 09:00:48

    Personal opinion, for reference only:
    First, you get MySQL done:
    1. Pull a mysql image
    2. Create a container: docker run --name=mysqlserver -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=yourpassword mysql

    • MYSQL_ROOT_PASSWORD=yourpassword: Password used to initialize mysqlserver

    Volume is not considered here. For security reasons, it is recommended not to store data in a container, or not in a mysqlserver container. You can use -v to share local storage or other containers specifically used to store data;
    3. Use root Use user and password to log in. You can decide what IP you want;

    Then, my approach to tomcat is:
    1. Install tomcat in an ubuntu14.04, and then expose the ubuntu container to the ssh port for easy use (some children think it is inappropriate, you should consider and learn this yourself);
    2. Configure tomcat related and deploy web applications:docker run -it -v /root/mnt_host:/root/mnt_container --name=myapp --link=mysqlserver:db -p 80:80 -p 4000:22 ubuntu:hardy /bin/bash

    • --link=mysqlserver:db: This allows tomcat to access mysql through db instead of ip;
    • -p 80:80: The 80% of myapp is exposed;

    After starting tomcat and everything is ok, you can access it through the host IP.

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-22 09:00:48

    You can write a Dockfile. You can also download a system and then install Tomcat, mysql and other required applications by yourself.

    reply
    0
  • Cancelreply