Docker错误Getaddrinfo:在Puma Nginx服务器-Mac OS中未知的名称或服务

时间:2019-03-12 10:54:27

标签: ruby-on-rails docker nginx docker-compose

运行docker run myapp时出现以下错误:

! Unable to load application: SocketError: getaddrinfo: Name or service not 
     known
     bundler: failed to load command: puma (/usr/local/bundle/bin/puma)

以下是我的配置和Dockerfile:

应用中的DockerFile

FROM ruby:2.5.0
# Set an environment variable where the Rails app is installed to inside of Docker image
ENV RAILS_ROOT /Users/admin/git/generic/myapp
ENV REDIS_URL=redis://redis:6379/0
RUN mkdir -p $RAILS_ROOT 
# Set working directory
WORKDIR $RAILS_ROOT
# Setting env up
ENV RAILS_ENV='production'
ENV RACK_ENV='production'
# Adding gems
#COPY ./Users/admin/git/generic/myapp/Gemfile ./Users/admin/git/generic/myapp/app/docker/app/Gemfile
#COPY ./Users/admin/git/generic/myapp/Gemfile.lock ./Users/admin/git/generic/myapp/app/docker/web/Gemfile.lock

COPY Gemfile Gemfile
COPY Gemfile.lock Gemfile.lock

RUN bundle install
# Adding project files
COPY . .
RUN gem install bundler
RUN bundle install
COPY . .
EXPOSE 3000
CMD ["bundle", "exec", "puma", "-C", "config/puma.rb","production"]

Web中的DockerFile

FROM nginx
# Install dependencies
RUN apt-get update -qq && apt-get -y install apache2-utils
# establish where Nginx should look for files
ENV RAILS_ROOT /Users/admin/git/generic/myapp
# Set our working directory inside the image
WORKDIR $RAILS_ROOT
# create log directory
RUN mkdir log
# copy over static assets
COPY public public/
# Copy Nginx config template
COPY docker/web/nginx.conf /tmp/docker.nginx
# put the final config in its place
RUN envsubst '$RAILS_ROOT' < /tmp/docker.nginx > /etc/nginx/conf.d/default.conf
EXPOSE 80
# Use the "exec" form of CMD so Nginx shuts down gracefully on SIGTERM (i.e.  `docker stop`)
CMD [ "nginx", "-g", "daemon off;" ]

我的Nginx配置

 upstream docker { 
     server 127.0.0.1:3000; 
 }

 server {  
     # define your domain  
     # define the public application root  
     listen 80;
     root   $RAILS_ROOT/public;  
     index  index.html;
     # define where Nginx should write its logs  
     access_log $RAILS_ROOT/log/nginx.access.log;  
     error_log $RAILS_ROOT/log/nginx.error.log;   


      # send non-static file requests to the app server  
      location / { 
          proxy_pass http://docker; 
      } 
} 

docker-compose.yml

version: '3'
volumes:  
  postgres_data: {} 

services:
  redis:
    image: redis
    command: redis-server
    ports:
      - "6379:6379"
  app:    
    build:      
      context: .      
      dockerfile: /Users/admin/git/generic/myapp/docker/app/DockerFile 
    depends_on:      
      - db  
  db:    
    image: postgres    
    volumes:      
      - postgres_data:/var/lib/postgresql/data  
  web:    
    build:      
      context: .      
      dockerfile: /Users/admin/git/generic/myapp/docker/web/DockerFile  
    depends_on:      
      - app    
    ports:      
      - 80:80

Puma.rb

workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['MAX_THREADS'] || 5)
 threads threads_count, threads_count

preload_app!

rackup      DefaultRackup
port        ENV['PORT']     || 3000
environment ENV['RACK_ENV'] || 'production'

on_worker_boot do
ActiveRecord::Base.establish_connection
end

任何人都可以帮助解决此Socket错误。本地主机已添加到我的主机文件中。我也尝试过更改nginx config。我仍然面临着同样的问题。

0 个答案:

没有答案