Dockerfile
FROM ruby:2.5 RUN apt-get update -qq && apt-get install -y nodejs postgresql-client RUN mkdir /myapp WORKDIR /myapp COPY Gemfile /myapp/Gemfile COPY Gemfile.lock /myapp/Gemfile.lock RUN bundle install COPY . /myapp # Add a script to be executed every time the container starts. COPY entrypoint.sh /usr/bin/ RUN chmod +x /usr/bin/entrypoint.sh ENTRYPOINT ["entrypoint.sh"] EXPOSE 3000 # Start the main process. CMD ["rails", "server", "-b", "0.0.0.0"]
docker-compose.yml
version: '3' services: db: image: postgres:10 volumes: - ./tmp/db:/var/lib/postgresql/data environment: TZ: Asia/Tokyo web: build: . environment: - "TZ=Asia/Tokyo" command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'" volumes: - .:/myapp ports: - "3000:3000" depends_on: - db
application.rb
require_relative 'boot' require 'rails/all' # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) module Myapp class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. config.load_defaults 5.2 # Settings in config/environments/* take precedence over those specified here. # Application configuration can go into files in config/initializers # -- all .rb files in that directory are automatically loaded after loading # the framework and any gems in your application. config.time_zone = 'Asia/Tokyo' config.active_record.default_timezone = :local end end
docker inspect 71204e91f20f | grep "TZ"をターミナルで実行した結果("71204e91f20f"は現在使用しているコンテナID)
"TZ=Asia/Tokyo",
解決したい問題
現在Dockerのコンテナ上でRailsを使いwebアプリを開発しているのですが、データーベースに保存されるデータの時間を日本時間にしたいです。
詳しく書くとcreated_at,update_atカラムに保存される時間を日本時間にしたいです。
コンテナ内の時間は日本時間になっていますが、データーベースに保存される値の時間だけ日本時間になっていません。
解決策を知る方ご教授願います。
情報が不足していたら何なりとお申し付けください。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/02/27 12:15