/til — Things I Learn

Things I have learned and want to remember, or that I think others might find useful. Some of these are links to articles from my postroll, while others are blog posts.

/postroll

Changing port maps in Docker Compose

akrabat.com

Rob details how to override and remove values in a Docker compose file when using a compose.override.yml or extending a value/service.

To just override it:

- ports: !override
  - "8081:80"

This is necessary, as otherwise if the value is already present in the original, the two settings get merged.

To remove:

- ports: !reset []

From the blog

Do you know the preferred Docker compose file name?

I've been using Docker for... a long time now. So having a docker-compose.yml file in a project is pretty natural and common for me.

Today I learned that the preferred file is now compose.yaml (though compose.yml is also allowed), and that the docker-compose naming is only supported for backwards compatibility. (See the Compose file documentation if you don't believe me!)

Funny enough, the compose tooling doesn't call this out, even though it now calls out the fact you don't need to use the version setting any more.

/postroll

Magento Cron via systemd timers | bitExpert

blog.bitexpert.de

Debian and Ubuntu are no longer shipping cron by default, and instead recommending setting up systemd timers. Stephan details how this is done, which requires both a systemd service file, and a systemd timer file.

The service file looks like this:

### Goes into /etc/systemd/system as a file with a .service extension
[Unit]
Description=Description of the service here
Wants=service-name.timer

[Service]
Type=oneshot
ExecStart=/path/to/executable/to/run/here
User=user-to-run-as
Group=group-to-run-as

[Install]
WantedBy=multi-user.target

You then create a timer, which is a systemd service defining a Timer section with an interval specified:

### Goes into /etc/systemd/system as a file with a .timer extension

[Unit]
Description=Executes every minute
Requires=service-name.service

[Timer]
Unit=service-name.service
OnCalendar=minutely

[Install]
WatnedBy=multi-user.target

The OnCalendar property can use "natural language" shortcuts like "minutely" or "hourly", or you can define date/time-based interval such as *-*-* *:*:00.

Once done, you need to start the service and enable the timer (usually as root):

systemctl start service-name.service
systemctl enable service-name.timer

and trigger it manually any time using:

systemctl start service-name.service

/postroll

Prevent the Docker container from taking 10 seconds to stop

akrabat.com

Rob Allen details how the exec form of a Docker CMD is the better form to use. The reason the string form invokes bash first, and thus bash gets PID 1, which is what Docker will terminate when the container is terminated. The problem is that bash doesn't then send a termination signal to the actual process invoked, forcing the Docker host to wait 10 seconds before force killing all processes in the container.

From the blog

Fixing Generation of wl-clipboard Transient Windows When Used with Neovim

Update, 2024-10-02: This actually does not fix the issue. I've yet to find a permanent solution.

For some reason, with a recent update to the wl-clipboard package or Neovim or both, I started seeing transient wl-clipboard windows, with a corresponding system notification, every time I'd do something that would write to a copy register in Neovim.

It was really annoying.

The fix turned out to be pretty easy in the end. Previously, I'd used this:

set clipboard+=unnamedplus

Switching it over to the following fixed the issue entirely:

set clipboard=unnamed,unnamedplus

From the blog

Using CloudFlare to Validate DNS For An ACM Certificate

I recently received a notification from AWS indicating that ACM certificates I had in place for some S3 buckets I expose for websites could not renew due to an inability to validate via DNS.

Figuring out how to make it work was non-trivial, so I'm writing it up so I can remember in the future, and maybe save somebody else some trouble, as everything I found had to do with auto-provisioning via Terraform.

From the blog

Copy A File From A Docker Container to the Host

Occasionally, I want to get a file from a Docker container back to the host system.

First, you need to get the container ID; you can do this using docker ps. Once you have that, use, docker cp as follows:

docker cp <containerId>:/path/to/file/in/container path/on/host

From the blog

Miscellaneous Postgres Commands

I switched over from SQLite to Postgres to power my site some months ago, and have found myself having to learn some new usage when interacting with the database. These are likely very old hat for anybody familiar with Postgres, but I find myself having to remind myself what they are.

/postroll

Chesterton’s Fence: A Lesson in Thinking

fs.blog

There is an adage attributed to G.K. Chesterton called "Chesterton's Fence" that can be abbreviated to this:

Do not remove a fence until you know why it was up in the first place.

I've read this article after a number of recent articles decrying the idea of "Founder's Mode" and other crappy entrepreneurial beliefs, and it struck a note with me. So many "disruptors" do not stop to understand why things operate as they currently do: what does having a taxi license solve for the community? what do environmental regulations solve for ecosystems? what additional regulations do hotels and other commercial lodgings need to abide by to protect consumers and employees? etc.

From the blog

Configuring PHP.INI settings in a PHP-FPM pool

I consume PHP via Docker primarily, and to keep it manageable, I generally use a PHP-FPM container, with a web server sitting in front of it. I learned something new about PHP configuration recently that (a) made my day, and (b) kept me humble, as I should have known this all along.

/postroll

gron

github.com

gron is a tool for working with JSON. It chunks things into key-value pairs where the key is a dot-separated hierarchy. This allows you then to use grep or ack to search for strings of interest.

It can also reassemble these back into JSON. This can be useful for adding or removing portions of a JSON structure. It becomes really interesting then when you pair it with jq in order to retrieve data back out.

As an example, I can get the list of development requirements from a composer.json with the following:

gron composer.json | ack "require-dev" | gron -u | jq '."require-dev" | keys[]'

(They'll still be in quotes, but that's easier to deal with than JSON keys!)

/postroll

Wezterm Quick Select Mode

wezfurlong.org

Quick select mode in Wezterm allows you to identify patterns in the current visible screen; Wezterm then highlights each and provides a key to each allowing you to copy and/or paste the associated value. Activate it with Ctrl-Shift-Space.

As examples:

  • It matches sha1 and md5 values. Use these to match a git ref in a log so you can then inspect it.
  • It matches Docker container identifiers; use these to match a container identifier so you can run a command in it or copy a file from or to it.
  • It matches URLs; use it to identify a URL to pass to HTTPie.
  • It matches paths; use it to match a path to perform a file operation on.