Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 671
user2707590 Avatar asked Apr 11 '20 13:04

user2707590


People also ask

Can Docker run on Google cloud?

Updating a container on a VM instance You can update a Docker image and configuration options to run the container on a VM instance using Google Cloud console or the Google Cloud CLI.


1 Answers

This can be done by creating a cloudbuild.yaml file in your project root directory. Add the following step to cloudbuild.yaml:

  steps:
  # running docker-compose
  - name: 'docker/compose:1.26.2'
    args: ['up', '-d']

On Google Cloud Platform > Cloud Builder : configure the file type of your build configuration as Cloud Build configuration file (yaml or json), enter the file location : cloudbuild.yaml

If the repository event that invokes trigger is set to "push to a branch" then Cloud Build will launch docker-compose.yml to build your containers.

like image 194
Ayoub BENSAKHRIA Avatar answered Sep 22 '22 04:09

Ayoub BENSAKHRIA