docker-composeにnginx、unicorn、railsを載せて環境構築をしています。下記のようにファイルを記述したのですが、pid = appname/tmp/unicorn.pid not writable (ArgumentError)
のように出てしまいました。 Dockerfileにtmp/pidsをmkdirするコマンドを書いたりしましたが、変わりませんでした。ご知見ある方がいらっしゃいましたらご助言の方お願いいたします。
Docekrfile
FROM ruby:3.0.2 RUN apt-get update -qq && \ apt-get install -y build-essential \ nodejs\ default-mysql-server\ default-mysql-client WORKDIR /appname COPY Gemfile /appname/Gemfile COPY Gemfile.lock /appname/Gemfile.lock RUN gem install bundler RUN bundle install RUN mkdir -p tmp/sockets RUN mkdir -p tmp/pids
docker-compose.yml
version: '3' services: app: build: context: . command: bundle exec unicorn -p 3000 -c /app-name/config/unicorn.rb depends_on: - db volumes: - .:/appname - public-data:/appname/public - tmp-data:/appname/tmp - log-data:/appname/log db: image: mysql:5.7 environment: MYSQL_ROOT_PASSWORD: password MYSQL_USER: user MYSQL_PASSWORD: password MYSQL_DATABASE: appname-development volumes: - db-data:/var/lib/mysql redis: image: redis:latest ports: - 6379:6379 volumes: - ./log:/var/log/redis - ./data/redis:/data command: redis-server --appendonly yes web: build: context: ./nginx_docker volumes: - public-data:/appname/public - tmp-data:/appname/tmp ports: - 80:80 depends_on: - app - redis volumes: public-data: tmp-data: log-data: db-data:
nginx_docker/Dockerfile
FROM nginx:1.15.8 RUN rm -f /etc/nginx/conf.d/* ADD nginx.conf /etc/nginx/conf.d/appname.conf CMD /usr/sbin/nginx -g 'daemon off;' -c /etc/nginx/nginx.conf
config/unicorn.rb
ruby
1$worker = 2 2$timeout = 30 3$app_path = File.expand_path('../../', __FILE__) 4puts $app_path 5$listen = File.expand_path 'tmp/sockets/unicorn.sock', $app_dir 6$pid = File.expand_path 'tmp/pids/unicorn.pid', $app_dir 7$std_log = File.expand_path 'log/unicorn.log', $app_dir 8# set config 9worker_processes $worker 10working_directory $app_path 11stderr_path $std_log 12stdout_path $std_log 13timeout $timeout 14listen $listen 15pid $pid 16# loading booster 17preload_app true 18# before starting processes 19before_fork do |server, worker| 20 defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect! 21 old_pid = "#{server.config[:pid]}.oldbin" 22 if old_pid != server.pid 23 begin 24 Process.kill "QUIT", File.read(old_pid).to_i 25 rescue Errno::ENOENT, Errno::ESRCH 26 end 27 end 28end 29# after finishing processes 30after_fork do |server, worker| 31 defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection 32end
nginx_dpcker/nginx.conf
upstream unicorn { #ユニコーンソケットの設定 server unix:/appname/tmp/sockets/unicorn.sock fail_timeout=0; } server { #IPとポートの指定 listen 80 default; #サーバーネームの指定 server_name localhost; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; #ドキュメントルートの指定 root /appname/public; client_max_body_size 100m; error_page 404 /404.html; error_page 505 502 503 504 /500.html; try_files $uri/index.html $uri @unicorn; keepalive_timeout 5; location @unicorn { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_pass http://unicorn; } }
あなたの回答
tips
プレビュー