I have a docker-compose.yml
file which specifies two services aaa
and bbb
as follows,
version: "3.4"
services:
aaa:
platform: linux/amd64
build: .
image: aaa
environment:
- ENV_VAR=1
volumes:
- ./data:/root/data
ports:
- 5900:5900
restart: on-failure
bbb:
image: bbb
build: ./service_directory
platform: linux/amd64
environment:
- PYTHONUNBUFFERED=1
volumes:
- ./data:/root/data
ports:
- 5901:5901
restart: on-failure
depends_on:
- aaa
I'm hoping to run both the above services simultaenously on a google cloud machine VM via cloudbuild.yaml
which reads,
steps:
- name: 'gcr.io/$PROJECT_ID/docker-compose'
args: ['up']
tags: ['cloud-builders-community']
My deployment script looks like
#!/bin/bash
container=mycontainer # container name
pid=my-nginx-363907 # process id
zone=us-west4-b
instance=instance-${zone} # instance name
gcloud builds submit \
--tag gcr.io/${pid}/${container} \
--project=${pid}
gcloud compute instances create-with-container ${instance} \
--zone=${zone} \
--tags=http-server,https-server \
--machine-type=e2-micro \
--container-image gcr.io/${pid}/${container} \
--project=${pid}
gcloud compute instances list --project=${pid}
Here's my directory structure:
project
| cloudbuild.yaml
| docker-compose.yml
| Dockerfile
|
|--service_directory
|
|--Dockerfile
The docker compose up
command does kick in, but it appears to build only service aaa
, and not bbb
. What's worse is that the service aaa
does not actually appear to run or have been installed in the VM instance. This is despite messages of apparent success:
ID CREATE_TIME DURATION SOURCE IMAGES STATUS
ab4785dd-7c4e-413d-acf6-1fdc64308387 2022-09-29T11:25:28 00:00 6M17S gs://my-nginx-363907_cloudbuild/source/1664450585.644241-04488e692b644a6186d922270dfbe667.tgz gcr.io/my-nginx-363907/aaa ( 1 more) SUCCESS
Can someone please explain how to run both the services on Google Cloud Compute Engine VM as specified by the docker-compose.yml
file?
CodePudding user response:
You probably need not use Cloud Build if you just want to run Docker Compose.
Cloud Build is often used (but not limited to) building container images.
You could (but need not) use Cloud Build to build the 2 container images that your docker-compose.yaml
uses (aaa
, bbb
) but you would need to revise the cloudbuild.yaml
to just perform the build
and push
steps and then you'd need to revise docker-compose.yaml
to consume the images produced by Cloud Build.
I think you should create a Compute Engine VM ensure that Docker, Docker Compose and your build content (.
) are available and then run your docker-compose.yaml
as you would on any Linux machine.