Skip to main content

Docker Compose

HowTo: Docker Compose yaml parse

anchors & aliases

bash -c "set -o allexport; source .env.local; yq eval-all --from-file internal/scripts/expand.yq docker-compose.yml docker-compose-local.yml" | yq -P 'sort_keys(..)' | tee private.yq.yml
  • docker compose provides shows internal representation. caveat: some sections maybe missing
docker compose --env-file .env.local --file docker-compose.yml --file docker-compose-local.yml config | yq -P 'sort_keys(..)' | tee private.dc.yml

grep

  • set DC_FILE
DC_FILE=docker-compose.yml
DC_FILE=docker-compose-local.yml
  • by serviceName
echo DC_FILE=$DC_FILE; cat $DC_FILE | yq -r '.services.* | (path | .[-1]) + " " + (.networks | @yaml | @json)' 
echo DC_FILE=$DC_FILE; cat $DC_FILE | yq -r '.services.* | (path | .[-1]) + " " + (.volumes | @yaml | @json)'
echo DC_FILE=$DC_FILE; yq '.services | with_entries(select(.key|test("alp-dataflow-gen-agent|alp-dataflow-gen"))) | .* | (path | .[-1]) + " " + (.networks | @yaml | @json)' $DC_FILE
for DC_FILE in docker-compose.yml docker-compose-local.yml; do echo DC_FILE=$DC_FILE; yq '.services | with_entries(select(.key|test("alp-dataflow-gen-agent|alp-dataflow-gen"))) | .* | (path | .[-1]) + " " + (.networks | @yaml | @json)' $DC_FILE; done
  • by prop
cat $DC_FILE | yq -o props '.services.*' | grep -E "container_name|volumes"

ports in use

export BASE_PORT=1
grep -oP "http.*${BASE_PORT:-1}.*" docker-compose.yml | envsubst | sort -u | awk -F: '{print $3}' | awk -F/ '{print $1}' | sed -e 's/"//' -e 's/,//' | sort -u

Issue: DNS lookup fails with Docker Compose multiple networks

Symptoms

Workaround

1 - Add dataflow-gen-agent-1 to alp network

  • edit docker-compose-local.yml
  • add the following to dataflow-gen-agent-1
network:
- alp

2 - Replace docker-compose binary

NEW_VERSION=v2.24.7
[[ "$(sysctl machdep.cpu.brand_string)" =~ Intel ]] && ARCH=x86_64 || ARCH=aarch64
URL=https://github.com/docker/compose/releases/download/$NEW_VERSION/docker-compose-darwin-$ARCH
DC_PATH=~/.docker/cli-plugins/docker-compose
DC_TMP=/tmp/docker-compose

OLD_VERSION=$($DC_PATH --version | awk '{print $NF}'); echo OLD_VERSION=$OLD_VERSION
mv -vf $DC_PATH $DC_PATH.$OLD_VERSION
curl -L -o $DC_TMP $URL
chmod u+x $DC_TMP
$DC_TMP --version
cp -vf $DC_TMP $DC_PATH
cp -vf $DC_PATH $DC_PATH.$NEW_VERSION
docker compose version
  • Caveat: change will revert if
    • restart docker desktop
    • click "Re-apply configurations"

Resolution

Issue: nodejs segmentation fault on MacOS x86_64 with Virtualization Framework enabled

Symptoms

docker logs --tail 1000 -f ${CONTAINER_NAME}
yarn run v1.22.22
$ ts-node updateEnvFiles.ts -s alp-minerva-db-mgmt-svc
Get client credentials token
Segmentation fault
error Command failed with exit code 139.
info Visit https://yarnpkg.com/en/docs/cli/run for

Workaround

  • Open Settings>General
  • Uncheck Use Virtualization framework & select gRPC FUSE

Docker-Desktop-disable-Virtualization-framework

Issue: nodejs segmentation fault on MacOS x86_64 with Virtualization Framework enabled

Symptoms

docker logs --tail 1000 -f ${CONTAINER_NAME}
yarn run v1.22.22
$ ts-node updateEnvFiles.ts -s alp-minerva-db-mgmt-svc
Get client credentials token
Segmentation fault
error Command failed with exit code 139.
info Visit https://yarnpkg.com/en/docs/cli/run for

Workaround

  • Open Settings>General
  • Uncheck Use Virtualization framework & select gRPC FUSE

Docker-Desktop-disable-Virtualization-framework

Resolution