Docker Behind Small SaaS

As a small SaaS who is pursing for quick iteration, we are using docker heavily for the deployment, it for sure makes our lives easier.

You can find kinds of beginning tutorial for Docker on the internet, and we’re sharing the instance how we use docker so that you can get a better view of it.

Tech Stacks

we are using node.js to build the backend with the framework express.js, sequelize.js for ORM, redis for session storage, postgres for the database, and docker-compose for organizing docker containers.

Dockerfile

Here we copy the project into the /app folder of the container, generating frontend-needed files and start the node application.

We copy package.json and yarn.lock first so that the docker can use node_modules caches in next building if we didn’t update the dependencies.

docker-compose.yml

We modified some values for security

As you can see in the file, we called our app container as web, linking each container by setting up depends_on, the environment of web container is available as process.env and environment of postgres container can initialize a new database with the pointed database name, username, and password.

Volumes used for data persistence. We stored user generated files(e.g., user uploaded files) and database data into the server disk so that we keep the data after restart the container.

DB migration

After running `docker-compose up -d`, we have started the app, initialized the database, but we still need to initialize the schemas of the database which can be done using sequelize.js:

you may have to add a correct config path and migration files path for the command, just check sequelize doc for more info.

Redeployment

We need to rebuild our docker every time we deploy a new feature with only 2 steps on the server:

Thanks to the Docker cache, everything is ready in a few minutes, and the app has updated online.

That is all

We doubt if docker is worthy of learning at the beginning because it looks like a tool for professional devops, but in fact, docker makes the deployment much more accessible and has worked quite stable so far.

Build your audience before building your product. We help people to make coming soon page 🔜

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store