Code Monkey home page Code Monkey logo

blitz-docker's Introduction

Blitz Docker

An example application with various configurations and setups to run Blitz with Docker.

Dockerfiles

Overview

The 'complete' Dockerfile is one large file that contains all the environments. There are also Dockerfiles available for specific environment if you only need those.
You can also mix and match the content of the Dockerfiles to create a custom one. The image sizes are based on a fresh Blitz app (0.35.0) like the one used in this repo. Sizes can vary depending on the Blitz version.

Type Base image Size
complete node:14-stretch-slim see below for each stage
prod-only node:14-stretch-slim 797MB
prod-only w/ BuildKit node:14-stretch-slim 612MB
[dev-only] node:14-stretch-slim
complete node:14-alpine See below for each stage
prod-only node:14-alpine 1.06GB

Build image

Place the Dockerfile that you want to use at the root of your application and run:

docker build . -t "IMAGE_NAME:TAG" \ 
  --build-arg DATABASE_URL="postgresql://user:password@host:port/db?sslmode=require&pgbouncer=true" \
	--build-arg SESSION_SECRET_KEY="yoursupersecretsessionkey"

If are using one of the 'complete' Dockerfiles and you want to stop at a specific stage you can do:

docker build . --target testing -t "IMAGE_NAME:TAG" \
	--build-arg DATABASE_URL="postgresql://user:password@host:port/db?sslmode=require&pgbouncer=true"
	--build-arg SESSION_SECRET_KEY="yoursupersecretsessionkey"

You can speed up the image build process and performance if you are using Docker v18.09 or later by using BuildKit. This is especially useful in combination with CI/CD. You can enable it by setting:

export DOCKER_BUILDKIT=1

Now you can build your image with one of the BuildKit Dockerfiles.

This is just a very basic way to build your image. You'll probably want to use CI/CD to automate this. An easy way to get started is this GitHub Action to build and push Docker images.

Docker Compose

Development

Place the docker-compose config file with the database that you want to use at the root of your application.
Currently you can choose between PostgreSQL and MySQL.

Production

  • Production* with remote database (managed on DO, AWS, Heroku etc.)
  • Production* with local database

* Docker Compose provides an easy way to deploy apps to production. This works fine for small and/or low-traffic apps on a single server.
If you need constant uptime, high-availability, load-balancing or anything like that you can check out some of the popular solutions. The easiest way to get started is by using Docker Swarm Mode (this is not Docker Classic Swarm which is deprecated). Other options are Kubernetes, which is offered as a managed service by most cloud providers, AWS ECS, Google Cloud Run or HashiCorp Nomad.

Best Practices

  • Use official images
  • Explicit image reference, avoid latest tag or generic aliases like node
  • Multistage builds
  • Non-root node user
  • Reduce the number of layers by merging RUN, FROM, and CMD commands.
    Using multiple COPY lines though to avoid that a change to a file invalidates the whole layer
  • No dev dependencies in production image
  • Delete caches
  • Use .dockerignore
  • Split long or complex RUN statements on multiple lines separated with backslashes to make the Dockerfile more readable,
    understandable, and more maintainable.

blitz-docker's People

Contributors

lorikarikari avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.