Skip to content

Instantly share code, notes, and snippets.

@MikaelElkiaer
Last active August 30, 2024 09:18
Show Gist options
  • Save MikaelElkiaer/024222aafa49cc9fc1dd767628fcfb28 to your computer and use it in GitHub Desktop.
Save MikaelElkiaer/024222aafa49cc9fc1dd767628fcfb28 to your computer and use it in GitHub Desktop.
Docker Compose config-volume-dependency-bug
configs:
config:
content: |
config
services:
volumer:
command:
- sh
- -c
- |
mkdir -p /tmp/volume
echo volume > /tmp/volume/test.txt
image: alpine
volumes:
- tmp:/tmp
without-config:
command:
- sh
- -c
- |
cat /tmp/volume/test.txt
depends_on:
volumer:
condition: service_completed_successfully
image: alpine
volumes:
- type: volume
source: tmp
target: /tmp/volume
volume:
subpath: volume
read_only: true
without-config-too:
command:
- sh
- -c
- |
echo touched-too
depends_on:
without-config:
condition: service_completed_successfully
image: alpine
with-config:
command:
- sh
- -c
- |
cat /tmp/volume/test.txt
cat /tmp/config.txt
# WARN: Seems to break the volume mount when run as a dependency
configs:
- source: config
target: /tmp/config.txt
depends_on:
volumer:
condition: service_completed_successfully
image: alpine
volumes:
- type: volume
source: tmp
target: /tmp/volume
volume:
subpath: volume
read_only: true
with-config-too:
command:
- sh
- -c
- |
echo touched-too
depends_on:
with-config:
condition: service_completed_successfully
image: alpine
volumes:
tmp:
@MikaelElkiaer
Copy link
Author

Running the scenarios:

#!/usr/bin/env bash

set -e

docker compose run --rm without-config
docker compose down --volumes

docker compose run --rm without-config-too
docker compose down --volumes

docker compose run --rm with-config
docker compose down --volumes

# Fails with:
# Error response from daemon: cannot access path /var/lib/docker/volumes/compose-config-bug_tmp/_data/volume: lstat /var/lib/docker/volumes/compose-config-bug_tmp/_data/volume: no such file or directory
docker compose run --rm with-config-too
docker compose down --volumes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment