How to run docker-compose on google cloud run?

Viewed 2992

I'm new to GCP, and I'm trying to deploy my spring boot web service using docker-compose. In my docker-compose.yml file, I have 3 services: my app service, mysql service and Cassandra service. Locally, It works like a charm. I added also a cloudbuild.yaml file :

steps:
- name: 'docker/compose:1.28.2'
  args: ['up', '-d']
- name: 'gcr.io/cloud-builders/docker'
  args: ['tag', 'workspace_app:latest', 'gcr.io/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA']
images: ['gcr.io/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA']

The build on Google cloud build is made with success. But, when I try to run the image on google cloud run, It doesn't call the docker-compose. How do I must process to use docker-compose on production?

3 Answers

With Cloud Run, you can deploy only one container image. The container can contain several binaries that you can run in parallel. But keep that in mind:

  • CPU is throttled when no request are processed. Background process/app aren't recommended on Cloud Run, prefer Request/Response app on Cloud Run (a webserver).
  • Only HTTP request are supported by Cloud Run. TCP connection (such as MySQL connection) aren't supported.
  • Cloud Run is stateless. You can't persist data in it.
  • All the data are stored in memory (directory /tmp is writable). You can exceed the total size of the instance memory (your app footprint + your files stored in memory)
  • Related to the previous point, when the instance is offloaded (you don't manage that, it's serverless), you lost all what you put in memory.

Thus, MySQL and Cassandra service must be hosted elsewhere

docker-compose -f dirfile/ cloudbuild.yaml up

and for check it write this command

docker images

and for check you conatiner

docker container ls -a 

and for check if container run or not write this command

docker ps

Finally, I deployed my solution with docker-compose on the google virtual machine instance. First, we must clone our git repository on our virtual machine instance. Then, on the cloned repository containing of course the docker-compose.yml, the dockerfile and the war file, we executed this command:

docker run --rm \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v "$PWD:$PWD" \
    -w="$PWD" \
    docker/compose:1.29.1 up

And, voila, our solution is working on production with docker-compose

Related