Last active
December 19, 2019 20:13
-
-
Save DonBattery/229153e04861de64700d359208c27b52 to your computer and use it in GitHub Desktop.
Docker + docker-compose + authenticated gcloud sdk for GCP Container Optimized OS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# based on: https://hub.docker.com/r/dduportal/docker-compose/dockerfile | |
# Usage | |
# set DOCKER_HOST to the remote machine | |
# copy your gcp_credfile.json to pwd | |
# $ docker build -t my-compose . | |
# $ docker run --rm -v /var/run/docker.sock:/var/run/docker.sock my-compose up -d --build --force-recreate | |
# As gcloud is authenticated with the supplyed credfile, and it's set as docker credential helper | |
# you can include your private containers from the GCP registry in the docker-compose.yaml file. | |
# You may further use the "my-compose" container to issue one-shot docker-sompose commands | |
# You can overwrite the docker-compose.yaml file with $ docker cp docker-compose.yaml my-compose:/app/docker-compose.yaml | |
FROM debian:8.4 | |
ENV DEBIAN_FRONTEND noninteractive | |
ENV COMPOSE_VERSION 1.25.0 | |
WORKDIR /app | |
# Install docker-compose | |
RUN apt-get update -q \ | |
&& apt-get install -y -q --no-install-recommends sudo curl ca-certificates\ | |
&& curl -o /usr/local/bin/docker-compose -L \ | |
"https://github.com/docker/compose/releases/download/${COMPOSE_VERSION}/docker-compose-Linux-x86_64" \ | |
&& chmod +x /usr/local/bin/docker-compose | |
# Install docker.io | |
RUN curl -sSL https://get.docker.com/ | sh | |
# Install gcloud cli | |
RUN echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" \ | |
| tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && curl https://packages.cloud.google.com/apt/doc/apt-key.gpg \ | |
| apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - && apt-get update -y && apt-get install google-cloud-sdk -y --force-yes | |
# Copy gcloud credfile | |
COPY gcp_credfile.json /app/gcp_credfile.json | |
# Copy docker-compose file | |
COPY docker-compose.yaml /app/docker-compose.yaml | |
# Activate gcloud service account | |
RUN gcloud auth activate-service-account --key-file=/app/gcp_credfile.json | |
# Set gcloud as a docker credential helper | |
RUN yes | gcloud auth configure-docker | |
# This container is a chrooted docker-compose | |
ENTRYPOINT ["/usr/local/bin/docker-compose"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment