Skip to content

Commit 11a77b1

Browse files
committed
updates for compose v2
1 parent 9257a4a commit 11a77b1

File tree

1 file changed

+12
-34
lines changed

1 file changed

+12
-34
lines changed
Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
# docker-compose
1+
# docker compose
22

3-
Around the time of the 2017 PMS guide I made the switch to `docker-compose` and it has been happily serving my container lifecycle needs ever since. Here's an screen recording example of updating the containers on the DigitalOcean droplet I use to run my personal blog.
3+
[docker compose](https://docs.docker.com/compose/) touts itself as a tool for managing and deploying multi-container applications. However, it excels at managing the application containers most of us will run on our PMS systems. Declaratively define the image, container name, volumes, ports, and so on that a container needs to run in a YAML file in a self-documenting system that saves you from that "how did I do this 6 months ago again?" question we've all faced at one time or another.
4+
5+
Compose is now part of the core docker package and as v2 (which was released in 2022) the `docker-compose` (note the hyphen) syntax was deprecated. All commands are now available via `docker compose` instead with no extra installations or configurations required.
6+
7+
Familiarise yourself with the [compose docs](https://docs.docker.com/compose/) as it is a very valuable tool on the belt of any self-hoster. I use it daily and it completely removes the need for any kind of container UI layer like portainer. Manage your config files via git (being careful not to commit any secrets) and you'll have a system that lasts for years. See [this video](https://www.youtube.com/watch?v=CUh8FDLbj8M) I made on how I manage my compose files using Ansible if you're curious.
8+
9+
Here's an screen recording example of updating the containers on the cloud VPS I use to run my personal blog, and this very website (plus a couple of other useful self-hosted services).
410

511
<figure markdown="span">
612
![compose-update-gif](../images/assets/compose.gif){ width="1280" }
713
</figure>
814

9-
## What is docker-compose?
10-
11-
docker-compose[^1] is a tool for defining and running multi-container Docker applications. With docker-compose, a YAML file is used to configure your application’s services. It enables you to use a single command to create, start, stop and destroy the services in your configuration file.
15+
## How do I use docker compose?
1216

13-
## How do I use docker-compose?
14-
15-
Here is an example `docker-compose.yaml` snippet for [Librespeed](https://github.com/librespeed/speedtest), a self-hosted speed test app.
17+
Here is an example `compose.yaml` snippet for [Librespeed](https://github.com/librespeed/speedtest), a self-hosted speed test app.
1618

1719
```yaml
1820
---
19-
version: "2"
2021
services:
2122
librespeed:
2223
image: linuxserver/librespeed
@@ -32,34 +33,11 @@ services:
3233
- PASSWORD=badger1
3334
```
3435
35-
YAML[^2] stands for Yet Another Markup Language and for correct parsing of these files careful attention to indentations made up of spaces are key. The specific number of spaces in the indentation is unimportant as long as parallel elements have the same left justification and the hierarchically nested elements are indented further.
36+
YAML[^2] stands for Yet Another Markup Language and for correct parsing of these files careful attention to indentations made up of spaces are key. The specific number of spaces in the indentation is unimportant as long as parallel elements have the same left justification and the hierarchically nested elements are indented further.
3637
3738
In short, make sure everything lines up vertically and you'll be OK. Use an editor which highlights spaces for bonus points. VSCode has some nice syntax plug-ins and YAML is one of them.
3839
39-
To create the container defined above copy and paste the above into a file placed at `~/docker-compose.yaml`, run `docker-compose up -d` and watch. When the output has finished updating, your Librespeed container will be accessible at `serverip:8008`. Try it out!
40-
41-
## Quality of life tweaks
42-
43-
Bash aliases make dealing with docker-compose much easier. Being a good sysadmin is about being fundamentally lazy and finding ways to reduce the amount of work you have to do. This is where bash aliases come in. Here are some primarily related to docker-compose:
44-
45-
```bash
46-
# /etc/bash_aliases
47-
# Aliases in this file are available to all users
48-
# To install for one user place in ~/.bash_aliases
49-
50-
# Tail last 50 lines of docker logs
51-
alias dtail='docker logs -tf --tail='50' '
52-
53-
# Shorthand, customise docker-compose.yaml location as needed
54-
alias dcp='docker-compose -f ~/docker-compose.yaml '
55-
56-
# Remove unused images (useful after an upgrade)
57-
alias dprune='docker image prune'
58-
59-
# Remove unused images, unused networks *and data* (use with care)
60-
alias dprunesys='docker system prune --all'
61-
```
62-
40+
To create the container defined above copy and paste the above into a file placed at `~/compose.yaml`, run `docker-compose up -d` and watch. When the output has finished updating, your Librespeed container will be accessible at `serverip:8008`. Try it out!
6341

6442
[^1]: [Docker - docker-compose](https://docs.docker.com/compose/)
6543
[^2]: [YAML.org - Spec](https://yaml.org/spec/)

0 commit comments

Comments
 (0)