ChaelCodes / chaelcodes.github.io

Portfolio site for ChaelCodes. Blogs, podcasts, and talks hosted here!
https://www.chael.codes
MIT License
2 stars 0 forks source link

Docker on Easy Mode (for Rails!) #76

Open ChaelCodes opened 2 years ago

ChaelCodes commented 2 years ago

Title:

Description

Let's learn about Docker, in the plainest, most pragmatic language possible.

Rough Draft of Content

Images

Images are a static version of an OS with all the dependencies installed. It also has an entrypoint or command that is run when it is used to create a container. Think of it as a stored blueprint for what a container should look like. Images have lots of sources, like dockerhub, or a local dockerfile. Even if you use an image from dockerhub, you can customize the entrypoint and environment variables. Examples:

Built from a local dockerfile

https://github.com/ChaelCodes/ConfBuddies/blob/05d74b62164e1f7099a5fda4f3ce0fe317da6ec0/docker-compose.yml#L2-L3

  web:
    build: .

https://github.com/ChaelCodes/ConfBuddies/blob/main/Dockerfile

Built from an image hosted at Docker Hub

https://github.com/ChaelCodes/ConfBuddies/blob/05d74b62164e1f7099a5fda4f3ce0fe317da6ec0/docker-compose.yml#L13-L14

  db:
    image: postgres:13

Container

A container is built using an image. It's a running instance that your other containers and local environment can connect to. You can create one-off containers using run or exec a command on an existing container.

Volumes

Often, you'll want to preserve changes that are made to your container, and see them in other containers. This is what volumes are used for! Volumes store information, like data in a database, or file changes locally. There are two types (I need to look up the real names) anonymous, and named volumes. Anonymous ones live someone in the docker runtime's appdata, and you don't have access to what's been stored outside docker. A named volume maps a file location on your computer to a volume. This is often used to bring in your app files into a container to be used.

Compose

Most applications use more than one container. They'll have elasticsearch, or redis too, and almost all of them have postgres or a database. Compose will bring up multiple containers at once, and understands which need to start first, and establishes a network between those containers so they can communicate.

When you run docker commands, you can add compose after docker, and it'll understand that you'd like to use a container from the compose network.