代码之家  ›  专栏  ›  技术社区  ›  makkasi

docker file命令从错误的存储库运行apt get update

  •  0
  • makkasi  · 技术社区  · 6 年前

    我不能安装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
    

    当我在UbuntuXenial上的时候,它似乎在尝试从Debian存储库中进行适当的更新。可能出了问题,因为我为Debian安装了第一个错误的Docker版本,然后我用

    sudo apt-get remove docker docker-engine docker.io
    sudo rm -rf /var/lib/docker
    

    在这之后,我为我的Ubuntu Xenial发行版安装了Docker。我不明白为什么当我运行Docker文件时,它仍然更新包并尝试安装Debian的包,当我没有任何与Debian相关的包时?

    安装的Docker版本是

    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...
    

    文档文件:

    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()"
    

    docker-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 回复  |  直到 6 年前
        1
  •  1
  •   BMitch    6 年前

    当我在UbuntuXenial上的时候,它似乎在尝试从Debian存储库中进行适当的更新。

    构建映像的命令将基于映像的先前状态在容器中运行。它们不依赖于您运行的主机。结果是相同的图像可以在不同的Docker主机上构建,结果几乎相同(外部依赖项和时间戳是正常的例外)。如果你按照你提供的dockerfile的路径 FROM 行,你得到:

    $ 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
    
        2
  •  1
  •   Alejandro Galera    6 年前

    我认为这是一个PostgreSQL版本的问题。 如果你在使用 stretch buster (buster实际上是从Stretch服务器更新的),repo中找到的版本是 PostgreSQL-客户端-9.6 不是9.5。

    试试这个,我们就知道了。