7

I have a classic Java webapp. It is composed of a database (PostgreSQL), a servlet container (Tomcat) and my code (deployed on Tomcat as a *.war file).

I want to package/deploy it using Docker (mostly for testing for now), but I'm unsure what would be the best way to "map" it.

My initial idea was to have an app-in-a-box - define a container that has Java, Postgres and Tomcat on it, exposing just the http port.

Further reading of the Docker docs shows that this, although possible (install and run supervisord as the single foreground process, have it start both Postgres and Tomcat) is probably not the intended usage. Going by the spirit of the tutorials I should probably create a container for Postgres, another for Tomcat, and a data-container to hold the application code (my *.war) and database files. This would mean 3+ containers (should the db files and *.war share the same data container?)

What's the common practice here?

Since I have no previous experience with Docker, what pitfalls can I expect from each approach?

Is there some other approach I'm missing?

7

The recommendations I've seen is to have all-in-one container: Docker Misconceptions:

Misconception: You should have only one process per Docker container!

It's important to understand that it is far simpler to manage Docker if you view it as role-based virtual machine rather than as deployable single-purpose processes. For example, you'd build an 'app' container that is very similar to an 'app' VM you'd create along with the init, cron, ssh, etc processes within it. Don't try to capture every process in its own container with a separate container for ssh, cron, app, web server, etc.

One way to think about it is to ask yourself if you'd ever need one piece running without the others. OK, maybe you'd want the DB running without the app server, but how often?

  • 1
    From the article you linked: "for most systems, you'll want role-based containers (app, db, redis, etc)" – CodesInChaos Nov 15 '14 at 15:47
9

Docker or not, I'd say don't put both webapp and db server in the same container. Initially, it may work, but if/as application grows, you'll want to scale the frontend and the database individually. Having different containers from the start will make it easier to move them around, duplicate them individually, etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.