お世話になっております。
下記の問題について知見のある方がいらっしゃいましたらご教示お願いします。
#起こっている問題
docker-compose up
実行時にrailsコンテナが起動しません。
エラーメッセージにはArgumentError: socket=/coffee_app/tmp/sockets/unicorn.sock specified but it is not a socket!
と書かれています。
$ docker-compose up Starting coffee_app_app_1 ... done Starting coffee_app_nginx_1 ... done Attaching to coffee_app_app_1, coffee_app_nginx_1 coffee_app_app_1 exited with code 1 nginx_1 | 2020/06/09 01:08:58 [error] 6#6: *1 connect() to unix:/var/tmp/unicorn.sock failed (111: Connection refused) while connecting to upstream, client: 172.18.0.1, server: coffeeapp-elb-16348812.ap-northeast-1.elb.amazonaws.com, request: "GET / HTTP/1.1", upstream: "http://unix:/var/tmp/unicorn.sock:/", host: "localhost" :
■unicorn.log
I, [2020-06-09T01:03:17.311665 #1] INFO -- : Refreshing Gem list F, [2020-06-09T01:03:21.797515 #1] FATAL -- : error adding listener addr=/coffee_app/tmp/sockets/unicorn.sock bundler: failed to load command: unicorn_rails (/usr/local/bundle/bin/unicorn_rails) ArgumentError: socket=/coffee_app/tmp/sockets/unicorn.sock specified but it is not a socket! /usr/local/bundle/gems/unicorn-5.4.1/lib/unicorn/socket_helper.rb:131:in `bind_listen' /usr/local/bundle/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:241:in `listen' :
#試したこと
■unicorn.sock再度作成
app/tmp/sockets直下に入っているユニコーンソケットを削除し、再度作成しましたが解決しませんでした。
#実行時の環境
AWS上のEC2にdockerを組み込み、nginxコンテナとrailsコンテナでアプリケーションを本番環境で起動させています。
AWSは下記を使用しています。
ECS、ECR、RDS、S3、VPC、EC2、ELB、Route53、IAM
#関連ファイル
coffee_app(アプリケーション)/config/unicorn.conf.rb
$worker = 2 $timeout = 30 $app_dir = "/coffee_app" $listen = File.expand_path 'tmp/sockets/unicorn.sock', $app_dir $pid = File.expand_path 'tmp/pids/unicorn.pid', $app_dir $std_log = File.expand_path 'log/unicorn.log', $app_dir # set config worker_processes $worker working_directory $app_dir stderr_path $std_log stdout_path $std_log timeout $timeout listen $listen pid $pid # loading booster preload_app true # before starting processes before_fork do |server, worker| defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect! old_pid = "#{server.config[:pid]}.oldbin" if old_pid != server.pid begin Process.kill "QUIT", File.read(old_pid).to_i rescue Errno::ENOENT, Errno::ESRCH end end end # after finishing processes after_fork do |server, worker| defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection end
coffee_app/docker/nginx/default.conf
upstream unicorn { server unix:/var/tmp/unicorn.sock; } server { listen 80; server_name coffeeapp-ELB-16348812.ap-northeast-1.elb.amazonaws.com; #charset koi8-r; #access_log /var/log/nginx/host.access.log main; location / { proxy_pass http://unicorn; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ .php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ .php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /.ht { # deny all; #} }
coffee_app/docker/nginx/nginx.conf
user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; server_names_hash_bucket_size 128; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; }
coffee_app/docker/nginx/Dockerfile
FROM nginx:1.12.2 RUN apt-get update && \ apt-get install -y apt-utils \ locales && \ echo "ja_JP.UTF-8 UTF-8" > /etc/locale.gen && \ locale-gen ja_JP.UTF-8 ENV LC_ALL ja_JP.UTF-8 ADD ./docker/nginx/nginx.conf /etc/nginx/nginx.conf ADD ./docker/nginx/default.conf /etc/nginx/conf.d/default.conf
coffee_app/docker/rails/Dockerfile
FROM ruby:2.5.1 RUN apt-get update && apt-get install apt-transport-https -y RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \ && echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list RUN apt-get update -qq && \ apt-get install -y apt-utils \ build-essential \ libpq-dev \ nodejs \ default-mysql-client \ yarn RUN mkdir /coffee_app WORKDIR /coffee_app ADD Gemfile /coffee_app/Gemfile ADD Gemfile.lock /coffee_app/Gemfile.lock RUN bundle install -j4 ADD . /coffee_app EXPOSE 3000
coffee_app/docker-compose.yml
version: '3' services: app: build: context: . dockerfile: ./docker/rails/Dockerfile command: bundle exec unicorn_rails -c /coffee_app/config/unicorn.conf.rb -E production # command: bundle exec unicorn_rails -c /coffee_app/config/unicorn.conf.rb ports: - '3001:3000' volumes: - tmp_data:/coffee_app/tmp/sockets - .:/coffee_app nginx: build: context: . dockerfile: ./docker/nginx/Dockerfile ports: - '80:80' volumes: - tmp_data:/var/tmp/ volumes: db_data: tmp_data:
#環境
ruby 2.5.1
rails 5.1.6
docker version 19.03.6
docker-compose version 1.24.0
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。