Docker文件命令从错误的存储库运行apt-get update

时间:2018-05-25 08:20:48

标签: docker ubuntu-16.04

我无法安装postgresql 9.5这是我在docker文件中的重点 Dockerfile行

RUN apt-get update && apt-get install -qq -y build-essential libpq-dev postgresql-client-9.5 --fix-missing --no-install-recommends

它运行命令下面。

remote: E: Package 'postgresql-client-9.5' has no installation candidate
remote:
 The command '/bin/sh -c apt-get update && apt-get install -qq 
-y build-essential libpq-dev postgresql-client-9.5 --fix-missing 
--no-install-recommends' returned a non-zero code: 100

当我在ubuntu xenial上时,它似乎试图从debian存储库进行apt-get更新。可能是出了问题,因为我为debian安装了第一个错误的docker版本,然后我用

删除了debian docker
sudo apt-get remove docker docker-engine docker.io
sudo rm -rf /var/lib/docker

在此之后,我为我的ubuntu xenial发行版安装了docker。我不明白为什么当我运行docker文件时它仍会更新软件包并尝试安装debian软件包,当我没有与debian相关的东西时?

已安装的泊坞窗版本为

Docker version 17.05.0-ce, build 89658be

来自https://apt.dockerproject.org/repo/pool/main/d/docker-engine/docker-engine_17.05.0~ce-0~ubuntu-xenial_amd64.deb

以下是运行apt-get update时的代码:

remote:  ---> Running in b8d8101adf4a
remote:  ---> f9286d1e85d1
remote: Removing intermediate container b8d8101adf4a
remote: Step 3/11 : RUN apt-get update && apt-get install -qq -y build-essential libpq-dev postgresql-client-9.5 mysql-client-5.7 --fix-missing --no-install-recommends
remote:  ---> Running in 9bda34235687
remote: Ign:1 http://deb.debian.org/debian stretch InRelease
remote: Get:2 http://deb.debian.org/debian stretch-updates InRelease [91.0 kB]
remote: Get:3 http://security.debian.org/debian-security stretch/updates InRelease [94.3 kB]
remote: Get:4 http://deb.debian.org/debian stretch Release [118 kB]
remote: Get:5 http://deb.debian.org/debian stretch-updates/main amd64 Packages [12.1 kB]
remote: Get:6 http://security.debian.org/debian-security stretch/updates/main amd64 Packages [440 kB]
remote: Get:7 http://deb.debian.org/debian stretch Release.gpg [2434 B]
remote: Get:8 http://deb.debian.org/debian stretch/main amd64 Packages [9530 kB]
remote: Fetched 10.3 MB in 13s (789 kB/s)
remote: Reading package lists...

Dockerfile:

FROM python:2.7
MAINTAINER Makkasi <makkasi@abv.bg>

RUN apt-get update && apt-get install -qq -y build-essential libpq-dev postgresql-client-9.5 --fix-missing --no-install-recommends

ENV INSTALL_PATH /project1
RUN mkdir -p $INSTALL_PATH

WORKDIR $INSTALL_PATH

COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt

COPY . .

VOLUME ["static"]
CMD gunicorn -b 0.0.0.0:8000 "project1.app:create_app()"

搬运工-compose.yml:

postgres:
  image: postgres:9.5
  environment:
    POSTGRES_USER: makkasi
    POSTGRES_PASSWORD: somepassword
  ports:
    - '5432:5432'
  volumes:
    - ~/.docker-volumes/project1/postgresql/data:/var/lib/postgresql/data


redis:
  image: redis:2.8.22
  ports:
    - '6379:6379'
  volumes:
    - ~/.docker-volumes/project1/redis/data:/var/lib/redis/data

project1:
  build: .
  command: gunicorn -b 0.0.0.0:8000 --reload --access-logfile - "project1.app:create_app()"
  environment:
    PYTHONUNBUFFERED: true
  links:
    - postgres
    - redis
  volumes:
    - .:/project1
  ports:
    - '8000:8000'

2 个答案:

答案 0 :(得分:1)

我认为这是一个postgresql版本的问题。 如果您正在使用stretchbuster(buster实际上是从stretch服务器更新),则在repo中找到的版本是 postgresql-client-9.6 ,而不是9.5。

试试这个,我们看到了。

答案 1 :(得分:1)

  

当我在ubuntu xenial上时,它似乎试图从debian存储库进行apt-get更新。

构建图像的命令基于图像的先前状态在容器内运行。它们不依赖于您运行的主机。结果是可以在不同的docker主机上构建相同的图像,结果几乎相同(外部依赖关系和时间戳是正常的例外)。如果您遵循从FROM行提供的Dockerfile路径,则会得到:

您还可以根据基本映像运行容器,并使用标准的包管理器工具来查询包含的软件包版本(当您没有为您的映像提供Dockerfile时,这非常有用):

$ docker run -it --rm python:2.7 /bin/bash

root@ea64878fc27f:/# cat /etc/debian_version
8.7

root@ea64878fc27f:/# apt-get update
Get:1 http://security.debian.org jessie/updates InRelease [94.4 kB]
Ign http://deb.debian.org jessie InRelease                   
Get:2 http://deb.debian.org jessie-updates InRelease [145 kB]              
Get:3 http://deb.debian.org jessie Release.gpg [2434 B]                            
Get:4 http://deb.debian.org jessie Release [148 kB]               
Get:5 http://security.debian.org jessie/updates/main amd64 Packages [623 kB]
Get:6 http://deb.debian.org jessie-updates/main amd64 Packages [23.0 kB]
Get:7 http://deb.debian.org jessie/main amd64 Packages [9064 kB]           
Fetched 10.1 MB in 9s (1058 kB/s)                                                                                    
Reading package lists... Done

root@ea64878fc27f:/# apt-cache search postgresql-client
postgresql-client-9.4 - front-end programs for PostgreSQL 9.4
postgresql-client - front-end programs for PostgreSQL (supported version)
postgresql-client-common - manager for multiple PostgreSQL client versions

root@ea64878fc27f:/# apt-cache madison postgresql-client
postgresql-client | 9.4+165+deb8u3 | http://deb.debian.org/debian/ jessie/main amd64 Packages
postgresql-client | 9.4+165+deb8u3 | http://security.debian.org/ jessie/updates/main amd64 Packages