postgresql - docker 中的 pg_dump 服务器和 pg_dump 版本不匹配

标签 postgresql docker docker-compose pg pg-dump

当我在 railsApp 容器中运行命令 psql --version 时,我得到 9.4.12 并且当我在其中运行相同的命令时postgres 容器,我得到 9.6.2。如何获得匹配的版本?

当我尝试在执行 pg_dump sql 导入的 Rails 应用程序上执行迁移时,出现以下错误。

pg_dump: server version: 9.6.2; pg_dump version: 9.4.12
pg_dump: aborting because of server version mismatch
rails aborted!

这是我的 Docker-compose.yml 文件:

version: "2.1"
services:
  railsApp:
    build:
      context: ./
    ports:
      - "3000:3000"
    links:
      - postgres
    volumes:
      - .:/app
  postgres:
    image: postgres:9.6
    ports:
      - "5432:5432"
    volumes:
      - ./.postgres:/var/lib/postgresql

Dockerfile:

FROM ruby:2.3.3

# setup /app as our working directory
RUN mkdir /app
WORKDIR /app

# Replace shell with bash so we can source files
RUN rm /bin/sh && ln -s /bin/bash /bin/sh

# Set debconf to run non-interactively
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections

# Install base dependencies

FROM ruby:2.3.3

# setup /app as our working directory
RUN mkdir /app
WORKDIR /app

# Replace shell with bash so we can source files
RUN rm /bin/sh && ln -s /bin/bash /bin/sh

# Set debconf to run non-interactively
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections

# Install base dependencies
RUN apt-get update && apt-get install -y -q --no-install-recommends \
        apt-transport-https \
        build-essential \
        ca-certificates \
        curl \
        git \
        libssl-dev \
        python \
        rsync \
        software-properties-common \
        wget \
        postgresql-client \
        graphicsmagick \
    && rm -rf /var/lib/apt/lists/*

# Install node and npm with nvm
RUN curl https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash

ENV NVM_DIR=/root/.nvm
ENV NODE_VERSION v7.2.1

ENV NODE_PATH $NVM_DIR/versions/node/$NODE_VERSION
ENV PATH      $NODE_PATH/bin:./node_modules/.bin:$PATH


RUN source $NVM_DIR/nvm.sh \
    && nvm install $NODE_VERSION \
    && nvm alias default $NODE_VERSION \
    && nvm use default

# Install our ruby dependencies
ADD Gemfile Gemfile.lock /app/
RUN bundle install

# copy the rest of our code over
ADD . /app

ENV RAILS_ENV development
ENV SECRET_KEY_BASE a6bdc5f788624f00b68ff82456d94bf81bb50c2e114b2be19af2e6a9b76f9307b11d05af4093395b0471c4141b3cd638356f888e90080f8ae60710f992beba8f

# Expose port 3000 to the Docker host, so we can access it from the outside.
EXPOSE 3000

# Set the default command to run our server on port 3000
CMD ["rails", "server", "-p", "3000", "-b", "0.0.0.0"]

最佳答案

同样的问题,我用了另一种方法来转储,

首先,我访问终端并在 docker 中运行 pd_dump,并将文件从 docker 复制到主机。 下面是命令

docker exec -it <container-id> /bin/bash # accessing docker terminal

pg_dump > ~/dump # taking dump inside the docker

docker cp <container-id>:/root/dump ~/dump #copying the dump files to host

希望以上解决方案有所帮助。

关于postgresql - docker 中的 pg_dump 服务器和 pg_dump 版本不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44768908/

相关文章:

postgresql - Heroku - 无法通过 Play Framework 应用程序设置 postgres 数据库?

sql - Rails 4 ActiveRecord 有很多通过关系无法从 sql 文件读取

docker - gitlab和taiga的反向代理-Docker

amazon-ec2 - ecs docker容器中celery worker的奇怪行为

postgresql - 无法在容器之间建立连接

创建函数时在创建时或接近创建时出现 postgresql 语法错误

xml - 如何在 PostgreSQL 中从 XML 查询兄弟节点

docker golang API ContainerList 因 TLS 而失败

docker - 如何通过 docker-compose 在容器之间共享卷

docker-compose - gitlab runner - 如何缓存图像而不是每次都构建?