Phantom007
Phantom007

Reputation: 2249

Best approach to create containers

I am developing an application with nodejs, mysql that has the following dependencies

I would like to know what would be the best approach if I want to use docker containers to pack my application.

Should I create one Nginx container, one nodejs container and one MySQL and make them talk to each other? I know this is a better approach since its scalable, but in this case how and where should I install ghostscript and pdftk? (the nodejs application makes use of Ghostscript and pdftk for pdf files)

or

should I create one ubuntu docker container and install everything (viz. Nginx, pdftk, Ghostscript, mysql) in it?

Upvotes: 1

Views: 89

Answers (2)

danielorn
danielorn

Reputation: 6147

Splitting an application up into separate containers requires a well defined API that support calls over the network (usually HTTP or some other application protocol on the TCP stack).

As both ghostscripts and pdftk are commandline tools invoked using a CLI you cannot call them from another container out of the box, you would need to develop some external facing API for that.

When setting the boundaries of your containers, think in terms of domains. The container becomes a the smallest unit that you will deploy and scale. That unit should be self contained and have a well defined, single purpose.

It is not clear from your description exactly what role nginx plays, but assuming that is some kind of client facing webserver or proxy, 3 containers makes sense in your case

  • NodeJs + PDFTK + Ghostscripts (The application)
  • Nginx (The webserver/proxy)
  • MySQL (The database)

The NodeJS application has all its application dependencies inside, but are more loosely coupled to Nginx and MySQL to whom it can communicate over the network.

Upvotes: 2

V. Mokrecov
V. Mokrecov

Reputation: 1094

You should create separate containers for each application, because this allows you to achieve:

  • Independent deploy.
  • Independent scaling.
  • Independent development.
  • Isolation and security.

For convenience, you can use docker-compose, which allows you to launch configure and launch multiple docker containers with a single command.

I would recommend that you deploy the database not in a Docker container in production because the database stores the state, it is also unreliable, and this increases the complexity of support.

Upvotes: 0

Related Questions