Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running docker-compose inside a Google Cloud Engine

I'm trying to run a small docker-compose app inside a container-optimized Google Cloud Compute Engine node, but I'm getting stuck when it's trying to mount volumes during a docker-compose up:

Creating lightning_redis_1 ... 
Creating lightning_db_1 ... 
Creating lightning_redis_1
Creating lightning_db_1 ... done
Creating lightning_api_1 ... 
Creating lightning_api_1 ... error
ERROR: for lightning_api_1  Cannot start service api: error while creating mount source path '/rootfs/home/jeremy/lightning': mkdir /rootfs: read-only file sys
tem
ERROR: for api  Cannot start service api: error while creating mount source path '/rootfs/home/jeremy/lightning': mkdir /rootfs: read-only file system
Encountered errors while bringing up the project.
jeremy@instance-1 ~/lightning $ 

My docker-compose.yml file looks like this:

version: '3'
services:
  client:
    build: ./client
    volumes:
      - ./client:/usr/src/app
    ports:
      - "4200:4200"
      - "9876:9876"
    links:
      - api
    command: bash -c "yarn --pure-lockfile && yarn start"
  sidekiq:
    build: .
    command: bundle exec sidekiq
    volumes:
      - .:/api
    depends_on:
      - db
      - redis
      - api
  redis:
    image: redis
    ports:
      - "6379:6379"
  db:
    image: postgres
    ports:
      - "5433:5432"
  api:
    build: .
    command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
    volumes:
      - .:/myapp
    ports:
      - "3000:3000"
    depends_on:
      - db

I don't want to have to change anything in the docker-compose.yml file - I'd prefer to be able to fix this issue by running commands inside the VM itself, or in how I set the VM up. Reason being is it's not my code and I can't change the docker-compose.yml file easily, and all I need to do is run it for a short period of time and execute a few docker-compose commands inside the VM.

like image 960
JeremyKirkham Avatar asked Sep 12 '17 10:09

JeremyKirkham


People also ask

Where can Docker containers be run in GCP?

You can run containers on Linux or Windows Server public VM images, or on a Container-Optimized OS image. Containers let your apps run with fewer dependencies on the host virtual machine (VM) and run independently from other containerized apps that you deploy to the same VM instance.


1 Answers

Container optimized OS usually mounts most of the paths as read-only. That is why you are getting the error

source path '/rootfs/home/jeremy/lightning': mkdir /rootfs: read-only file sys

So you have few options

Use named volumes in docker-compose

You will need to change your volumes like below

volumes:
  - myappvol:/myapp

and define the top level volumes in compose

volumes:
  myappvol: {}

As you said you don't want to modify the yaml then this may not work for you

Run docker-compose inside docker

Currently you run docker-compose on the main machine, instead you should use docker-compose inside another docker container which has the main root folder

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

This would work but the data would be persisted inside the docker container itself.

See below article for more details

https://cloud.google.com/community/tutorials/docker-compose-on-container-optimized-os

like image 149
Tarun Lalwani Avatar answered Oct 19 '22 16:10

Tarun Lalwani