Skip to content

Latest commit

 

History

History

1 - Docker

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

PoC Software Pool 2024 - Day 04 - Docker

Day purposes

✔️ Understand DevOps interests.

✔️ Learn the basics of Docker.

✔️ Create a simple image.

✔️ Deploy a complete stack with docker compose.

Introduction

When it's time to deploy an application, you will face various problems:

  • How scale on various servers?
  • How build your app for several architectures?
  • How manage dependencies and linked services that work with your app?

For instance, if you want to deploy a simple application composed of a web server, a frontend and a database, you will need to install all the required dependencies in the server, maybe update root config and create system services to automatically restart it on fail, manage volumes and so on...

You've understood it, manually manage a stack is complex and painful.
This is why Docker exist, with it you can easily package your application into containers that you can manage independently or together.

This dynamic follows the way of DevOps, it's a philosophy and set of practices to improve the delivery process from build to release and monitoring.

Here's a simple schema of the devops workflow:

devops workflow

This subject is focused on docker and containers building & management. It's one the most important part of DevOps.

Step 0 - Setup

Please refer to the SETUP.md file.

Step 1 - Dockerfile

Dockerfile is the first piece to containerize your application.
The purpose is to create an image of your application to make it easily deployable 😃

This will help you to avoid installing the application directly on the computer and having dependencies issues.
With an image, you can't have any of these problems, it's self deployable and everything is already installed in it, you just have to run it with docker run <image>.

Let's create an image of the API you made yesterday 🚀

First, in your pool repository, in the folder day04, create a folder docker.

mkdir -p day04/docker

Now you can create a directory step1, copy-paste yesterday API sources and create a file Dockerfile.

Your Dockerfile must execute the following set:

  • Pull the latest alpine image of your language.
  • Expose port 8080
  • Install dependencies
  • Set the environment variable HELLO_MESSAGE to docker
  • Build the API
  • Set the entrypoint to start the server when running the image.

⚠️ Be careful to the listening API host.

Take a look at those good practices 😉

Step 2 - Docker compose

In the previous step, you saw how to put your application in a container, it's time to go further: you will manage multiple containers with docker compose.

Create a directory step2:

mkdir -p step2

The purpose is to manage a fullstack application within containers.
This application is composed of:

Here's a simple schema of the application architecture:

front-back-db

Lay the foundations

In the directory step2, copy the frontend and backend zips and extract them.

You should end up with the following architecture:

tree -d
# .
# ├── backend
# │   ├── src
# │   │   └── notes
# │   └── test
# └── frontend
#     ├── cypress
#     ├── public
#     └── src
#         ├── components
#         │   ├── List
#         │   ├── Task
#         │   └── TaskForm
#         ├── dto
#         └── services
#
# 13 directories

Dockerfiles

As you may notice, there is no Dockerfile in frontend or backend.
You figured out, you will need to create images for the frontend and the backend.
In each directory, create a Dockerfile and write a set of instructions to make it work.

💡 You will need to test and understand how each program work to containerize it.
Google is also your best friend, as a DevOps engineer it's common to work on multiple stack without necessarily being an expert on them.

Compose

Docker compose aims to orchestrate services. It will help you a lot when you need to deploy multiple microservices.

Your docker-compose file must be composed of:

3 services:

  • backend: run the backend image
  • frontend: run the frontend image
  • database: run the postgres image

1 network:

  • backend: link database & backend in a private network

1 volume:

  • db-data: store database permanent data

To complete this step, you'll need to use all the knowledge acquired during previous day. It will be important to set an environment to correctly configure the database, backend and frontend in the docker-compose.

Don't forget to exposed ports and link your services 😄

This step is voluntarily complex to make you search and understand by yourself, this is what real DevOps engineers do 🚀

Additional resources

Organization


LinkedIn logo Instagram logo Twitter logo Discord logo

Website logo

🚀 Don't hesitate to follow us on our different networks, and put a star 🌟 on PoC's repositories.