I have docker-compose project for Rails depends on mongo. I need to run mongorestore during build before CMD in dockerfile runs the rails server. How I can do that?
I tried https://stackoverflow.com/a/66069362/4011757 but it doesn't start the mongorestore.
The server doesn't start says collections not found needed to start it. So it is necessary to have mongorestore before start of the server
Dockerfile
FROM ruby:2.3.0
RUN apt-get update -qq && apt-get install -y nodejs npm
RUN npm install --global coffeescript
WORKDIR /
COPY Gemfile /Gemfile
COPY Gemfile.lock /Gemfile.lock
RUN mkdir -p /log && touch /log/development.log
RUN gem install bundler -v "1.17.3"
RUN bundle install
COPY . /
CMD ["sh", "-c", "bundle exec padrino start"]
docker-compose.yml
version: '3.4'
services:
mongo:
image: mongo:3.2.4
container_name: 'tickets-mongo'
volumes:
- ./mongorestore.sh:/docker-entrypoint-initdb.d/mongorestore.sh
- ./db:/db
ports:
- 27017:27017
redis:
image: redis:alpine
container_name: redis
depends_on:
- mongo
ports:
- 6379:6379
volumes:
- redis_data:/var/lib/redis
elasticsearch:
image: elasticsearch:7.9.2
container_name: 'tickets-elasticsearch'
environment:
- discovery.type=single-node
depends_on:
- redis
ports:
- 9200:9200
volumes:
- elasticsearch_data:/usr/share/elasticsearch/data
app-worker:
env_file:
- .env_development.env
build: .
container_name: tickets-worker
depends_on:
- elasticsearch
links:
- mongo:mongo
- redis:redis
- elasticsearch:elasticsearch
app:
env_file:
- .env_development.env
build: .
container_name: tickets-web
depends_on:
- app-worker
links:
- mongo:mongo
- redis:redis
- elasticsearch:elasticsearch
ports:
- 3000:3000
volumes:
mongo: {}
redis_data: {}
elasticsearch_data: {}