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?

  • How to dockerized java microservices efficiently
  • mounting docker-machine VM folders in container with docker-compose
  • distributed wide and deep with tf.contrib.learn api example stuck on k8s
  • Docker install memcached
  • Installation of chef-client(Bootstrapping) on docker container in a VM on Azure/AWS
  • What docker image use for ionic CD / e2e testing? Ubuntu or just node?
  • Can't kill supervisord inside of docker container
  • No suitable driver found for jdbc:postgresql when trying to connect spark-shell (inside a docker container) to my PostgreSQL database
  • Downloading Gradle in Docker Container
  • Using Docker, how do you execute PHP composer commands?
  • Where is docker's apparmor profile?
  • Docker daemon fails to start: inotify_add_watch: no such file or directory
  • 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.