Since GCE's Container-Optimized OS does not include docker-compose
by default.
We have to use the official docker/compose image as a workaround.
However, docker/compose
cannot access GCR or GAR to pull private images.
Therefore we have to create a custom docker-compose image which is authenticated to GCR / GAR.
mkdir docker-compose-gar && cd docker-compose-gar
FROM docker/compose:alpine-1.27.4
ENV VERSION=2.0.2
ENV OS=linux
ENV ARCH=amd64
# Install docker-credential-gcr
RUN wget -O - "https://github.com/GoogleCloudPlatform/docker-credential-gcr/releases/download/v${VERSION}/docker-credential-gcr_${OS}_${ARCH}-${VERSION}.tar.gz" \
| tar xz --to-stdout ./docker-credential-gcr > /usr/bin/docker-credential-gcr && chmod +x /usr/bin/docker-credential-gcr
RUN docker-credential-gcr version
RUN docker-credential-gcr configure-docker --include-artifact-registry
CMD docker-compose
docker build -t docker-compose-gar .
echo alias docker-compose="'"'docker run --rm \
-v /var/run/docker.sock:/var/run/docker.sock \
-v "$PWD:$PWD" \
-w="$PWD" \
docker-compose-gar'"'" >> ~/.bashrc
Now you can pull the private images from GCR / GAR
Try:
docker-compose pull
or
docker-compose up