DOCKER:无法连接到服务器:无法分配请求的地址

时间:2019-06-11 07:50:27

标签: port docker ubuntu-16.04 postgresql ruby-on-rails

我已经尝试了多种方法来解决此问题,但我不知道在哪里再次遇到类似的错误……

! Unable to load application: PG::ConnectionBad: could not connect to server: Connection refused
    Is the server running on host "localhost" (127.0.0.1) and accepting
    TCP/IP connections on port 5432?
could not connect to server: Cannot assign requested address
    Is the server running on host "localhost" (::1) and accepting
    TCP/IP connections on port 5432?

这是我的DOCKERFILE

FROM ruby:2.2.2
# Install node.js

RUN apt-get -y install curl
RUN mkdir -p /usr/local/nvm
ENV NVM_DIR /usr/local/nvm
ENV NODE_VERSION 8.15.1

RUN curl 
https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash \
&& . $NVM_DIR/nvm.sh \
&& nvm install $NODE_VERSION \
&& nvm alias default $NODE_VERSION \
&& nvm use default

 ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules
 ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH
 ENV GEM_HOME="/usr/local/bundle"
 ENV PATH $GEM_HOME/bin:$GEM_HOME/gems/bin:$PATH

 RUN node -v
 RUN npm -v

 RUN echo -e "s/[#]\?listen_addresses = .*/listen_addresses = '*'/g" -i '/etc/postgresql/9.5/main/postgresql.conf'
 RUN echo -e "host    all    all    0.0.0.0/0    md5" >> sudo /etc/postgresql/9.5/main/pg_hba.conf

 # Install global Ruby dependencies
 RUN gem install bundler -v '1.17.3'

 ADD . .
  # Install Ruby gems
  RUN bundle install
  EXPOSE 3001
  # Stop on SIGINT (Ctr-C)
  STOPSIGNAL SIGINT

这是我的docker-compose.yml

 services:
   server:
    build:
  context: .
  dockerfile: Dockerfile
image: universum-businessprofile:local
depends_on:
  - db
  - redis
  - openssl
ports:
  - "3001"
  volumes:
  # This volume is just to simplify development process and not to rebuild image after each change
  - ./:/app
  # The following volume is required for communication between server and jobs
  - ./public:/app/public
env_file:
  - ./.env
environment:
  - ACCESS_YEAR
  - BP_URL
  - REDIS_PORT
  - REDIS_HOST
  - EMPLOYEES_MFOS
  - DIR_RANKING_YEAR
  - META_RANKING_YEAR
  - RDS_DB_NAME
  - RDS_USERNAME
  - RDS_PASSWORD
  - RDS_HOSTNAME
  - RDS_PORT
  - SENTRY_API
  - SIDEKIQ_USERNAME
  - SIDEKIQ_PASSWORD
  - SUPER_MAIL_ID
  - TABULATOR_API_URL
  - TABULATOR_USERNAME
  - TABULATOR_PASSWORD
  - UA_API_URL
  - USE_SENRTY
  - USE_SSL
restart: always
command: ./bin/run_local_server.sh
 jobs:
image: universum-businessprofile:local
depends_on:
  - db
  - redis
ports:
  - "3001"
volumes:
  # This volume is just to simplify development process and not to rebuild image after each change
  - ./:/app
  # The following volume is required for communication between server and jobs
  - ./public:/app/public
env_file:
  - ./.env
environment:
  - ACCESS_YEAR
  - BP_URL
  - REDIS_PORT
  - REDIS_HOST
  - EMPLOYEES_MFOS
  - DIR_RANKING_YEAR
  - META_RANKING_YEAR
  - RDS_DB_NAME
  - RDS_USERNAME
  - RDS_PASSWORD
  - RDS_HOSTNAME
  - RDS_PORT
  - SENTRY_API
  - SUPER_MAIL_ID
  - TABULATOR_API_URL
  - TABULATOR_USERNAME
  - TABULATOR_PASSWORD
  - UA_API_URL
  - USE_SENRTY
restart: always
command: ./bin/run_local_jobs.sh
 redis:
  image: redis:3.2
  ports:
  - "6379"
  restart: always
  db:
    # In production we use 9.4.20 (and we are going to upgrade it to 10.4)
image: postgres:10.7
volumes:
  - ./ci/db/:/docker-entrypoint-initdb.d
ports:
  - "5432"
restart: always
 openssl:
  image: frapsoft/openssl
volumes:
  - ./tmp:/export
command: req -new -newkey rsa:2048 -sha1 -days 365 -nodes -x509 -subj "/C=US/ST=Colorado/L=Colorado Springs/O=SW/CN=localhost.ssl" -keyout /export/localhost.key -out /export/localhost.crt
restart: "no"

这是我的evn文件

    BP_URL=http://localhost:3001/
    DB_PORT=5432
    DIR_RANKING_YEAR=2016
    JOBS_PORT=3002
    REDIS_PORT=6379
    REDIS_HOST=redis
    RDS_DB_NAME=businessprofile_dev_1
    RDS_USERNAME=postgres
    RDS_PASSWORD=postgres
    RDS_HOSTNAME=db
    RDS_PORT=5432
    SERVER_PORT=3001
    SIDEKIQ_USERNAME=sidekiqadmin
    SIDEKIQ_PASSWORD=UniversumBP
    UA_API_URL="http://localhost:3000/api/"

0 个答案:

没有答案