Skip to content

[Overview] Docker

Anh Tu Do edited this page Sep 9, 2023 · 2 revisions

Main link

https://www.docker.com/

What is Docker?

Docker is a platform that provides the ability to package and run an application in a loosely isolated environment called a container

Containers are a lightweight way to package an application and its dependencies so the application runs quickly and reliably from one computing environment to another

The good thing about this container is that imagine you are building an app, you can create a database, a server, and public assets (eg. images) inside one container. So whenever you want to develop, all you need to do is hit one single command, and your app together with its dependencies will be up and running

It's also easy for other developers on your team to replicate your app if they have your docker-compose.yml file

What is the flow of Docker?

1. Create docker-compose.yml

The most simple flow is first to create a docker-compose.yml file. This file will contain what services you want available in your container environment

For example, if you want to host a local Postgres database, you might want something like this:

version: "3.8"

services:
  db:
    image: postgres
    restart: always
    ports:
      - 5432:5432
    environment:
      POSTGRES_DB: gdyo
      POSTGRES_USER: gdyo
      POSTGRES_PASSWORD: gdyo
    volumes:
      - postgres-volume:/var/lib/postgresql/data

volumes:
  postgres-volume:

There are a lot of images (or packaged services) out there on Docker. Do you know that you can create and publish one yourself using Dockerfile?

But that is something unnecessary for now and you might want to explore more in your free time :)))

2. Create your container

You can do so by simply running docker-compose up or making your Docker container run in the background with docker-compose up -d

After this step, if you open your Docker Desktop app, you should see a container running