Tag: docker
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
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.
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
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
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.