Docker, howdy as automation

Skip to content

This here’s a machine-translated text that might contain errors!

Docker makes deployin’ applications simpler than a Sunday mornin’. Instead of installin’ and configurin’ software by hand on a server, ya define everythin’ in configuration files. The result is reproducible, portable, and quick to get up and runnin’.

What in tarnation is Docker Compose?

With Docker Compose, ya define a whole mess o’ services in a single file (docker-compose.yml). Each service is a container with its own setup, see?

services:
  web:
    image: nginx:latest
    ports:
      - "80:80"
  grafana:
    image: grafana/grafana:latest
    ports:
      - "3000:3000"

One command sets up ever’thin’:

docker compose up -d
# Starter alle tjenester i bakgrunnen.
# Starts all services in the background.

Need ta move the service to another server? Copy the file and run the same command. Everything’s identical.

Why This Here’s Automation?

Now, consider the difference:

Manual Setup With Docker Compose
Install Nginx manually image: nginx:latest
Configure ports ports: "80:80"
Install Grafana manually image: grafana/grafana:latest
Document all the steps Everything’s documented in the .yml file
Repeat everything on the next server docker compose up -d

That Docker Compose file is the documentation. It describes exactly which services are runnin’, what ports they use, and how they’re configured.

Handy Docker Commands

Command What it does
docker compose up -d Starts all services in the background
docker compose down Stops and removes all containers
docker compose logs -f Follows the logs in real time
docker compose pull Pulls the latest version of all images
docker compose restart Restarts all services
docker ps Shows running containers

Volumes: Savin’ Yer Data Outside the Container

Containers are temporary, see? If ya go ‘n delete a container, all its contents just up ‘n vanishes. To keep yer data safe, we use volumes:

services:
  database:
    image: postgres:16
    ports:
      - "5432:5432"
    environment:
      POSTGRES_PASSWORD: hemmelig # This here is the password for the database, keep it safe, ya hear?
    volumes:
      - db-data:/var/lib/postgresql/data

volumes:
  db-data:

Here, the database files are stored in a volume called db-data. Even if ya go ‘n delete ‘n recreate the container, the data’s still there.

Updatin’ Services

Updatin’ a Docker service is plumb simple:

# Get latest version
docker compose pull

# Restart with new version
docker compose up -d

Now, reckon this here’s like fixin’ up software ya installed by yer own two hands – ya gotta download, configure, and just pray nothin’ breaks.

Easy Task 1 - Get Nginx Runnin’ with Docker Compose

Create a docker-compose.yml to run an Nginx web server:

  1. Make a new folder and create the file docker-compose.yml
  2. Define a service with image: nginx:latest on port 80
  3. Run docker compose up -d
  4. Visit http://localhost in yer browser

Medium Task 2 - Add a Service

Expand the docker-compose.yml from task 1 with an extra service. For example:

Start everything with docker compose up -d and see that both services are runnin’ at the same time.

Summation

  • Docker Compose lets ya define a whole mess o’ services in a single file
  • The Compose file is both yer configuration and documentation, see?
  • Volumes store data outside the container so it survives restarts
  • Updatin’ is docker compose pull + docker compose up -d
  • Docker makes it easy to move services ‘tween servers