how can we create full stack application like frontend backend and database one docker image

Viewed 170

I'm beginner in docker can anyone help me in how can we create full stack application like frontend backend and database one docker image

1 Answers

It's not a recommended to host all in one container. Usually one service will have it's own container. Let's take an example suppose you are using following for your app

  • Backend (Php or NodeJS or Python)
  • Frontend (Vue or React)
  • Database (Postgres Or Mysql)
  • Caching Service (Redis or Memcache)
  • Webserver (Apache or Nginx)

This is just an example. Here you will create individual container for Backend, Frontend, Database, Cache and WebServer. This will ensure that your services will not fail due to any other dependencies and also this will encapsulate/isolate the containers and error handling is more easier. You will usually communicate between apps by exposing ports.

But sometimes you might want to share some data between two service. eg: If you are using your local machine for file storage then you might want the folder to be given access to Backend and Webserver (for exposing assets). In this case you will use volumes for this.

TLDR: If you absolutely want to host it in a single dockerfile then you can use multistage build for this and use a ubuntu or alpine container and install all the package you need and expose the ports.

Related