I am trying to use a Percona Docker image for MongoDB on GCE, however I'm running into an issue with Mongo saying the mounted path is read-only. I looked around as much as I could, but im stumped at what could be the issue.
gcloud compute instances create-with-container mongo-svr \
--create-disk name=disk-1,size=1GB \
--container-mount-disk mount-path="/data/mongodb",mode=rw \
--container-image=docker.io/percona/percona-server-mongodb:4.2
I used the above command and it creates my instance. I then SSH into the server, connect to the running mongo instance to shutdown, then I run: docker exec -it [NAME] mongod --configsvr --replSet rs0 --dbpath=/data/mongodb --bind_ip localhost
This spits out an error stating:
CONTROL [initandlisten] options: { net: { bindIp: "localhost" }, replication: { replSet: "rs0" }, sharding: { clusterRole: "configsvr" }, storage: { dbPath: "/data/mongodb" } }
STORAGE [initandlisten] exception in initAndListen: IllegalOperation: Attempted to create a lock file on a read-only directory: /data/mongodb, terminating
At this point, I've been recreating instances with different params, but nothing has worked so far. Anyone have an idea what I'm missing?
Updated with command output
gcloud compute instances create-with-container mongo-config-f --zone us-central1-f --create-disk name=disk-1,size=1GB --container-mount-disk mount-path="/data/mongodb" --container-image=docker.io/percona/percona-server-mongodb:4.2 --machine-type=f1-micro
WARNING: Default device-name for disk name [disk-1] will be [disk-1] because it is being mounted to a container with [`--container-mount-disk`]
Created [https://www.googleapis.com/compute/v1/projects/[PROJECT_NAME]/zones/us-central1-f/instances/mongo-config-f].
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
mongo-config-f us-central1-f f1-micro xx.xx.xx.xx xx.xx.xx.xx RUNNING
I've tried to replicate your issue on my test project and found that:
persistent disk was created and mounted in read-write mode as expected;
docker runs containers inside our VM properly;
the cause of the error while running
docker exec -it [NAME] mongod --configsvr --replSet rs0 --dbpath=/data/mongodb --bind_ip localhostis permissions inside mongodb container:As a workaround commands could be executed with root permissions:
Please find more details and my steps below:
create VM:
SSH to instance;
check if container is running:
everything looks good at this point;
try to run command as user:
and observe the same error:
here key read-only directory: /data/mongodb;
check mounts and permissions inside of the container:
as we expected disk was created and mounted in read-write mode to the container
but to work with
/data/mongodbyou needrootpermissions;try to run command as root:
and it's working with root permissions.