Can't drop-in Percona-Server-MongoDB image without errors

I am currently creating a Docker Container with the following image:

FROM mongo
EXPOSE 27017

This pulls the latest mongo official docker image from DockerHub.
I was hoping to drop-in percona’s mongo image to replace the official, but I’m running into an issue. This is what the dockerfile looks like:

FROM percona/percona-server-mongodb
EXPOSE 27017

The container builds fine, but when I try to spinup my deployment environment with docker compose up, I get the following issue:

mongo_1     | {"t":{"$date":"2022-06-27T17:05:17.030+00:00"},"s":"E",  
"c":"CONTROL",  "id":20557,   "ctx":"initandlisten",
"msg":"DBException in initAndListen, terminating",
"attr":{"error":"IllegalOperation: Attempted to create a lock file on a read-only directory: /data/db"}
}

Once the lock file error happens, everything shuts down

2 Likes

I fixed the above issue by changing permissions on the database/ collection within my deployment folder. This is not an issue I had in the past with mongo’s image, so I’m unsure as to why I’m getting it now.

Anyways, even with this issue fixed, I’m still having errors replacing the official mongo image with the Percona-Server-MongoDB container. I am currently getting a ECONNREFUSED for localhost:27017 MongoNetworkError

1 Like

The problem is that the directory you created, /data/db is owned by and only writable by the root user, but you are running mongod as yourself. There are several ways to resolve this, but ultimately, you must give the directory in question the right permissions. For example:

sudo chmod -R go+w /data/db
sudo chown -R $USER /data/db

As for the latter issue, ECONNREFUSED error: There are few reasons for this error in node :

  1. Your port is already occupied so it will refuse your connection. Go to the command line and get PID by using the following command:
$ lsof -i:port_number`

Now kill pid by using:

$ kill -9 pid

(you will get paid by the previous command)

  1. There is also the possibility you need to run mongod --repair
1 Like