How to deploy container using docker-compose to google cloud?

4/11/2020

i'm quite new to GCP and been using mostly AWS. I am currently trying to play around with GCP and want to deploy a container using docker-compose.

I set up a very basic docker-compose.yml file as follows:

# docker-compose.yml
version: '3.3'

services:
  git:
    image: alpine/git
    volumes:
      - ${PWD}:/git
    command: "clone https://github.com/PHP-DI/demo.git"

  composer:
    image: composer
    volumes:
      - ${PWD}/demo:/app
    command: "composer install"
    depends_on:
      - git

  web:
    image: php:7.4-apache
    ports:
      - "8080:${PORT:-80}"
      - "8000:${PORT:-8000}"
    volumes:
      - ${PWD}/demo:/var/www/html
    command: php -S 0.0.0.0:8000 -t /var/www/html
    depends_on:
      - composer

So the container will get the code from git, then install the dependencies using composer and finally be available on port 8000.

On my machine, running docker-compose up does everything. However how can push this docker-compose to google cloud.

I have tried building a container using the docker/compose image and a Dockerfile as follows:

FROM docker/compose

WORKDIR /opt
COPY docker-compose.yml .

WORKDIR /app
CMD docker-compose -f /opt/docker-compose.yml up web

Then push the container to the registry. And from there i tried deploying to:

  1. cloud run - did not work as i could not find a way to specify mounted volume for /var/run/docker.sock
  2. Kubernetes - i mounted the docker.sock but i keep getting an error in the logs that /app from the git service is read only
  3. compute engine - same error as above

I don't want to make a container by copying all local files into it then upload, as the dependencies could be really big thus making a heavy container to push.

I have a working docker-compose and just want to use it on GCP. What's the easiest way?

-- user2707590
docker
docker-compose
google-cloud-platform
google-cloud-run
google-kubernetes-engine

2 Answers

4/12/2020

Take a look at Kompose. It can help you convert the docker compose instructions into Kuberenetes specific deployment and services. You can then apply the Kubernetes files against your GKE Clusters. Note that you will have to build the containers and store in Container Registry first and update the image tag in service definitions accordingly.

-- Agasthi
Source: StackOverflow

4/12/2020

Compute engine is basically a virtual machine so just log in via ssh and install docker and docker-compose. After that docker-compose up will run with no problem just like on your local machine.

-- Grzegorz Pudłowski
Source: StackOverflow