Is it possible to deploy multiple docker images onto a Google Container-Optimized OS (COS) in GCP

405 Views Asked by At

I have a github actions workflow which builds and pushes the docker images to container registry on GCP. Post that it deploys the images onto compute engine. Currently three images are being deployed on three separate VMs. The goal is to have these on the same VM machine.

Tried to Manually create the VMs on the GCP but it lets me add only one image so far. Please help me with the settings or how I can create a VM that can host several Images on it. If not, please suggest a best way to overcome this situation.

1

There are 1 best solutions below

0
On

It is possible via cloud-init, below is an example.

Add the below custom metadata to the GCE instance running COS, this will start two containers in the same instance.

    key: "user-data"
    value: "#cloud-config\nruncmd:\n  - /usr/bin/docker run -d busybox /bin/sleep 1000\n  - /usr/bin/docker run -d nginx /bin/sleep 1000"

Then restart the instance to have the changes take effect, and run below commands to test after that.

    $ docker ps
        CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS     NAMES
        d7e8a9b707a6   nginx     "/docker-entrypoint.…"   14 minutes ago   Up 14 minutes   80/tcp    fervent_austin
        0b116788132c   busybox   "/bin/sleep 1000"        14 minutes ago   Up 14 minutes             elated_ardinghelli