0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

本番環境のcronでcan't connect to local mysql serverになる

Posted at

状況

cronを使ってサイトマップを定期的に更新したいと思いcronコンテナを追加。
開発環境は無事動いたが、なぜか本番環境でうまく動かない。

  • dockerで新たにcronコンテナを作成
  • DBのコンテナは存在せず、外部のDBサーバーを利用

事象

本番環境でcronを利用して、rake 'sitemap:refresh'実行した際にcan't connect to local mysql serverというエラーが出る。

原因

docker-compose.ymlのcronにDB情報を記載していなかった。

解決策

cronに以下のようなenvironmentを追加

cron:
    build: .
    volumes:
      - .:/app
    depends_on:
      - app
    restart: always
    command: cron -f
    environment:
      - 'APP_DATABASE_NAME=${DB_NAME}'
      - 'APP_DATABASE_USER=${DB_USER}'
      - 'APP_DATABASE_PASSWORD=${DB_PASSWORD}'
      - 'APP_DATABASE_HOST=${DB_HOST}'
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?