I have a docker-compose file which looks like:
version: "3"
services:
mongoDB:
restart: unless-stopped
volumes:
- "/data/db:/data/db"
ports:
- "27017:27017"
- "28017:28017"
image: "andresvidal/rpi3-mongodb3:latest"
mosquitto:
restart: unless-stopped
ports:
- "1883:1883"
image: "mjenz/rpi-mosquitto"
FG:
privileged: true
network_mode: "host"
depends_on:
- "mosquitto"
- "mongoDB"
volumes:
- "/home/pi:/home/pi"
- "/boot:/boot"
image: "arkfreestyle/fg:v1.8"
entrypoint: /app/docker-entrypoint.sh
restart: unless-stopped
I'm using a mongoDB container for the raspberry pi built by someone else (I just pulled it from docker-hub), the issue is if for any reason there is an improper shutdown, the container fails to deal with the mongod.lock file in the /data/db directory.
In this case, upon trying to restart all containers, the mongodb container keeps exiting with status code 100, and the only way to fix it is to manually remove the lock file by running: sudo rm /data/db/mongod.lock in my terminal. However, I wish to automate this and run this command in my docker-compose file, either before the mongodb container starts or if it's attempting to restart.
I don't want to mess with mongodb's Dockerfile because it's built by someone else (is it good practice to make changes in other people's Dockerfiles btw?), so I want to use my docker-compose file. I can't use the entrypoint or command options because I don't want to override any default commands in the Dockerfile, I just want to run this extra command without messing with anything else:
sudo rm /data/db/mongod.lock
And I want to run this either before the mongodb container starts (worst case it will just output no file found), or if mongodb is trying to restart.
I'm open to more ideas on how you recommend tackling this issue as well, so any help is appreciated!