Search results

From the blog

Posted 2025-04-04
Overriding values when merging Docker Compose config

I've recently started using the ability to merge Docker Compose files, as it reduces repetition when having different configuration for production from development. This also helps reduce cases where configuration gets updated in one, but not the other, leading to issues when debugging why something runs in one environment but not another.

Generally, when overriding something in development, I'm overriding volumes and environment variables. I started also using the fact that the env_file directive can take a list of files, which allows segregating environment variables by context, allowing re-use of specific variables between services, so that I don't go polluting services with ENV variables that it doesn't use.

The problem I ran into, however, is that on a particular service, I have production env variable files in a secure, global location, but in development, I use a single .env file. When these get merged, because the value is a list, I was getting complaints in development that one or more env files did not exist.

Since I knew I wanted to keep just the one entry in development, I needed a way to tell Compose to use only the value in that file.

Turns out this is well supported via the !override directive:

### In my development compose YAML:
services:
    app:
        env_file: !override
            - .env

/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

Posted 2024-09-25
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

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

Posted 2024-09-20
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

Posted 2018-11-04
Fixing Redis background-save issues on Docker

I've been running redis in Docker for a number of sites, to perform things such as storing session data, hubot settings, and more.

I recently ran into a problem on one of my systems where it was reporting:

Can't save in background: fork: Out of memory

From the blog

Posted 2018-11-01
Building a usable ext-tidy for Alpine-based PHP Docker images

I've been working on building PHP Docker images for the purposes of testing, as well as to potentially provide images containing the Swoole extension. This is generally straight-forward, as the official PHP images are well-documented.

This week, I decided to see if I could build Alpine-based images, as they can greatly reduce the final image size. And I ran into a problem.

Search tips

  • Use #{some tag} or tag:{some tag} to filter by tag; using this more than once will find results that match all tags.
  • Use year:{year} to filter by year. If you use this multiple times, the last one wins.
  • Use begin:{year-month-day} to restrict to results beginning on that day. Last one wins.
  • Use end:{year-month-day} to restrict to results ending on that day. Last one wins.