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?

  • Can't connect nodejs and mysql in same docker
  • Does AWS ECS support per container dynamic scalability?
  • In docker cpu usage calculation what are: TotalUsage, SystemUsage, PercpuUsage and what does the calculation means?
  • Docker's `docker0` device dies repeatedly (`inet addr` disappears)
  • How to link docker host to container by name
  • How can one influence the order of RUN commands in a Dockerfile?
  • Django models foreign key not recognizing 'QueryString' BaseObject
  • Docker - Should my MySQL database live inside or outside the container?
  • Unable to run flask app in debug mode using Docker
  • Docker: Error starting container: Unable to load the AUFS module
  • Docker ERROR: Error processing tar file(exit status 1): unexpected EOF
  • Docker Networking - nginx: [emerg] host not found in upstream
  • 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.