我使用whenever
gem设置了cron任务,crontab的所有功能都正常。但是,当docker启动时,它不会启动cron
服务。我需要进入容器并手动运行cron
以运行该服务。我跟着其他问题和他们的指示,但他们似乎并没有为我工作。
Dockerfile
FROM ruby:2.3.3
# setup /app as our working directory
ENV RAILS_ROOT /app
RUN mkdir -p $RAILS_ROOT
# Set working directory, where the commands will be ran:
WORKDIR $RAILS_ROOT
# Replace shell with bash so we can source files
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
# Set debconf to run non-interactively
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
# Install base dependencies
RUN apt-get update && apt-get install -y -q --no-install-recommends \
apt-transport-https \
build-essential \
ca-certificates \
curl \
git \
libssl-dev \
python \
rsync \
software-properties-common \
wget \
wget ca-certificates \
cron \
&& rm -rf /var/lib/apt/lists/*
# Installing the Postgres - This specific version so it doesn't throw the version mismatch when we do `pg_dump`
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" | tee /etc/apt/sources.list.d/postgres.list
RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
RUN apt-get update
RUN apt-get install --assume-yes postgresql-9.6
# Install node and npm with nvm
RUN curl https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash
ENV NVM_DIR=/root/.nvm
ENV NODE_VERSION v7.2.1
ENV NODE_PATH $NVM_DIR/versions/node/$NODE_VERSION
ENV PATH $NODE_PATH/bin:./node_modules/.bin:$PATH
RUN source $NVM_DIR/nvm.sh \
&& nvm install $NODE_VERSION \
&& nvm alias default $NODE_VERSION \
&& nvm use default
# Install our ruby dependencies
ADD Gemfile Gemfile.lock $RAILS_ROOT/
RUN bundle install
# Install the cronjob logger
RUN touch /var/log/swscd-cron.log
# copy the rest of our code over
ADD . $RAILS_ROOT
ENV SECRET_KEY_BASE a6bdc5f788624f00b68ff82456d94bf81bb50c2e114b2be19af2e6a9b76f9307b11d05af4093395b0471c4141b3cd638356f888e90080f8ae60710f992beba8f
RUN bundle exec whenever --update-crontab
RUN bundle exec rake assets:precompile
# Expose port 3000 to the Docker host, so we can access it from the outside.
EXPOSE 3000
# Set the default command to run our server on port 3000
CMD cron && rails s -p 3000 -b 0.0.0.0