Express REST API with Docker

Álvaro José Agámez Licha

Fullstack Developer at Zagalabs

Docker

Before WSL 2, working with Docker on Windows was not a very easy option, but now everything works like a charm, thanks to the fact that WSL 2 actually includes a full Linux kernel and Microsoft worked hand by hand with the Docker Team to make this integration possible.

 

The first step is download and install Docker Desktop 2.3.0.2 or a later release and restart your computer.

Docker

Now we need to add our local user to the docker-users group to be able to run Docker Desktop.  To do this we need to run the following commands in a Powershell console with administrator privileges.

# With this Powershell command we get our username
PS > Get-LocalGroupMember -Group "Users"

PS > Add-LocalGroupMember -Group "docker-users" -Member "COMPUTER-ID\username"

Docker

Because we will Docker with a standard user, we need to execute docker-compose with sudo inside WSL.

$  sudo docker-compose up -d

Agenda

  1. I will be focus on code, so I will explain a boilerplate that I built for this application type and after that we will create the code for the API.
  2. I will explain my docker and docker-compose strategy and why I do this.
  3. I will show you some tools that I use for my docker development.
  4. Questions.

Boilerplate

The boilerplate have some structure and configurations to make a quick start. I try to follow a series of good practices for Express applications and others on how to structure a REST API.

Docker

We have to reduce the possibility to expose sensitive information, so we NEVER owe this kind of information in Docker or docker-compose files.

 

For this reason I set all the sensitive a docker-compose.override.yml that NEVER is stored in the Git repository.

Tools

  1. WSL: I personally use WSL to develop, because I was TIRED of dealing with VPNs in Linux.
  2. DockStation: For me the best docker GUI client, I used in Linux and now in Windows.
  3. VS Code: Nothing new to add for the best OpenSource IDE.
  4. Postman: Really powerfull tool to test our APIS.  Insomnia is another very good option.

Ready to Write Some Great Code

Made with Slides.com