Docker tips

Posted by Jonas Sandström on Fri 01 January 2021

Here are 3 usefull tips for working with Docker when developing APIs or backends. If you haven't red Dockers own Getting started tutorial I recomend doing this first.

This post is a short rundown of how I would go about. From local development to creating a production ready Docker container.

1. Use Docker Compose for local development

docker-compose makes it easy to run your service with all parts (frontend, backend, database etc) as one entity. This makes it possible to test in a very production like setting. However I do not recomend relying too much on specific details like relying on the internal networking of Compose, unless this is similar to how you will handle networking on your production server.

2. Build a Docker image via your build pipline.

No matter if you are using Github, Gitlab, Bitbucket, or something similar take advanteg of thier build piplines. Building and tagging a Docker image automatically for all successfull builds (mabye only for a specific branch?) makes it so that no single developer is responsible for building the image, ie no implicit knowledge is required (and you don't have to call that "dev ops person" who is on vaccasion) in order to make a hot fix.

3. Think about Security - don't run as root

Even tough Docker is built with Decopuling of system in mind it's always possible to get hacked, and if that happends, if somone gets access to your container, running the container as a non-root user will limit their access to other services.