當我在自己的機器上使用Docker時,我想訪問我的系統的Postgres。這是將我的圖像部署到AWS的地方,我想使用RDS。如何從Docker訪問我的本地系統Postgres
我遵循Docker's Quickstart: Docker Compose and Rails page的步驟,除了因爲我正在使用現有的應用程序,我沒有創建剛加載Rails的初始最小Gemfile。
泊塢窗容器外,Postgres的已安裝並正常工作:無碼頭工人
$ which postgres
/Applications/Postgres.app/Contents/Versions/latest/bin/postgres
$ which pg_restore
/Applications/Postgres.app/Contents/Versions/latest/bin/pg_restore
$ which pg_dump
/Applications/Postgres.app/Contents/Versions/latest/bin/pg_dump
該應用程序已工作的罰款多年。爲了測試泊塢窗容器外部的應用程序,一旦多了,我有註釋掉多克的建議docker-compose.yml
文件的一行如下:
development: &default
adapter: postgresql
encoding: unicode
database: postgres
pool: 5
username: postgres
password:
# host: db
test:
<<: *default
database: myapp_test
當我這樣做,我可以運行rake db:test:clone
(例如)在容器外無後顧之憂:
但是,當我取消這條線,並連接到一個TTY在容器中,我在各種疼痛:
/myapp# rake db:test:clone
pg_dump -s -x -O -f /myapp/db/structure.sql postgres
Please check the output above for any errors and make sure that `pg_dump` is installed in your PATH and has proper permissions.
/myapp# which postgres
/myapp# which pg_restore
/myapp# which pg_dump
/myapp#
我能做些什麼?
的Dockerfile的基礎上,碼頭工人與我現有的應用程序需要一些額外的二進制文件,說明是:
FROM ruby:2.3.1-slim
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
RUN apt-get update
RUN apt-get install -qq -y --no-install-recommends --fix-missing apt-utils
RUN apt-get install -qq -y --no-install-recommends --fix-missing build-essential
RUN apt-get install -qq -y --no-install-recommends --fix-missing git
RUN apt-get install -qq -y --no-install-recommends --fix-missing xvfb
RUN apt-get install -qq -y --no-install-recommends --fix-missing qt5-default
RUN apt-get install -qq -y --no-install-recommends --fix-missing libqt5webkit5-dev
RUN apt-get install -qq -y --no-install-recommends --fix-missing gstreamer1.0-plugins-base
RUN apt-get install -qq -y --no-install-recommends --fix-missing gstreamer1.0-tools
RUN apt-get install -qq -y --no-install-recommends --fix-missing gstreamer1.0-x
RUN apt-get install -qq -y --no-install-recommends --fix-missing nodejs
RUN apt-get install -qq -y --no-install-recommends --fix-missing libpq-dev
RUN mkdir /myapp
WORKDIR /myapp
ADD Gemfile /myapp/Gemfile
ADD Gemfile.lock /myapp/Gemfile.lock
RUN bundle install
ADD . /myapp
相關:我可以看到redis-cli
容器外,但不是在它裏面。一旦我解決了Postgres的情況,這也將是一個問題。
更新
當我走在這樣的...
docker-compose run web rake db:create
docker-compose run web rake db:test:clone
...看來我可以訪問Postgres的,但不是pg_dump
,並且在需要rake db:test:clone
,rake db:test:load
或類似的其他實用程序。
更新II
添加以下到Dockerfile:
RUN apt-get install -qq -y --no-install-recommends --fix-missing postgresql-client
現在,而不是給我一個 「無法找到」 的錯誤,它說:
pg_dump: server version: 9.5.4; pg_dump version: 9.4.9
pg_dump: aborting because of server version mismatch
這是一個您可以在其他地方找到的問題,但不在Docker的背景下討論,這在這裏非常重要。
如果我將我的Mac的Postgres降級到apt-get
獲取的版本,會有幫助嗎?通過升級安裝apt-get
的版本似乎不是一個選項:
Step 15 : RUN apt-get install -qq -y --no-install-recommends --fix-missing postgresql-client-9.5
---> Running in 614b88701710
E: Unable to locate package postgresql-client-9.5
E: Couldn't find any package by regex 'postgresql-client-9.5'
謝謝。原則上這看起來應該起作用。 (但是,Docker文檔也是如此。)但最終我最終沒有使用Docker部署到ElasticBean。 –