What should a dockerfile contain to run a simple CRUD web application?

I am studying Docker and to understand better, I want to use it to run a Java web application that I created a while ago. It uses Java, Spring, Hibernate on back-end and Spring MVC on front-end, and MySQL as a database. In Eclipse, it can be easily run on Tomcat and opened in a browser. In essence, it’s a simple CRUD application.

In order to create a dockerfile to run it, do I need to start with (FROM) an OS image? How do I include Java, MySQL and Tomcat instances? How can I configure it to run the application war?

  • Docker + Django + MySQL - End of list of non-natively partitioned tables
  • Run a service automatically in a docker container
  • DC/OS JMX Access
  • Docker volumes are partitions or subdirectories?
  • Change Docker for windows to use another VM besides MobylinuxVM
  • Docker - browsing to docker container using its IP
  • Start container in existing cgroup
  • `docker attach` command can't enter into a container unless Ctrl+C or Enter pressed
  • Docker container to NAS Storage
  • Docker Service Separation
  • docker rabbitmq hostname issue
  • PULL Docker container/image
  • One Solution collect form web for “What should a dockerfile contain to run a simple CRUD web application?”

    The standard Docker style is to have a single service per container and then have an orchestration tool manage the containers as a group.

    Docker comes with a tool called Docker Compose that is configured with a docker-compose.yml file.

    version: '2'
        build: ./web/
         - "8080:8080"
         - myapp_net
        build: ./db/
         - myapp_data:/var/lib/mysql
         - myapp_net
        driver: bridge


    It will be easiest if you start your Dockerfiles from existing images so you don’t have to deal with complete builds. Most popular open source software will have images available on Docker Hub. Searching ” docker” will normally be the top result. Have a look at the Dockerfile from the images you use. The official images tend to use all the current best practices.

    The mysql image gives you a blank mysql installation with some custom configuration options. You might not need a Dockerfile here initially.


    FROM mysql:5.7
    RUN some-setup.sh

    The tomcat image supplies a working OpenJDK and Tomcat installation for you to deploy your app to.


    FROM 8.0-jre8-alpine
    COPY myapp.war /usr/local/tomcat/webapps/myapp.war
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.