apt-add-repository:在Dockerfile中找不到命令错误


92

我只是在终端中制作了一个非常简单的Docker文件,基本上我做了以下工作:

mkdir pgrouted
cd pgrouted
touch Dockerfile

现在,我在nano编辑器中打开Docker文件,并将以下命令添加到Docker文件中:

FROM ubuntu

MAINTAINER Gautam <gautamx07@yahoo.com>

LABEL Description="pgrouting excercise" Vendor="skanatek" Version="1.0"

ENV BBOX="-122.8,45.4,-122.5,45.6"

# Add pgRouting launchpad repository
RUN sudo apt-add-repository -y ppa:ubuntugis/ppa
RUN sudo apt-add-repository -y ppa:georepublic/pgrouting
RUN sudo apt-get update

# Install pgRouting package (for Ubuntu 14.04)
RUN sudo apt-get install postgresql-9.3-pgrouting

# Install osm2pgrouting package
RUN sudo apt-get install osm2pgrouting

# Install workshop material (optional, but maybe slightly outdated)
RUN sudo apt-get install pgrouting-workshop

# For workshops at conferences and events:
# Download and install from http://trac.osgeo.org/osgeo/wiki/Live_GIS_Workshop_Install
RUN wget --no-check-certificate https://launchpad.net/~georepublic/+archive/pgrouting/+files/pgrouting-workshop_2.0.6-ppa1_all.deb

RUN sudo dpkg -i pgrouting-workshop_2.0.6-ppa1_all.deb

# Review: Not sure weather this should be in the dockerfile
RUN cp -R /usr/share/pgrouting/workshop ~/Desktop/pgrouting-workshop

# Log in as user "user"
RUN psql -U postgres

# Create routing database
RUN CREATE DATABASE routing;

# Add PostGIS functions
RUN CREATE EXTENSION postgis;

# Add pgRouting core functions
CREATE EXTENSION pgrouting;

# Download using Overpass XAPI (larger extracts possible than with default OSM API)
wget --progress=dot:mega -O "sampledata.osm" "http://www.overpass-api.de/api/xapi?*[bbox=${BBOX}][@meta]"

整个Dockerfile可以在这里一目了然。

现在,当我尝试构建Dockerfile时,如下所示:

docker build -t gautam/pgrouted:v1 .

Dockerfile运行,然后出现以下错误:

Step 4 : RUN sudo apt-add-repository -y ppa:ubuntugis/ppa
 ---> Running in c93c3c5fd5e8
sudo: apt-add-repository: command not found
The command '/bin/sh -c sudo apt-add-repository -y ppa:ubuntugis/ppa' returned a non-zero code: 1

为什么会出现此错误?

Answers:


121

apt-add-repository不在基础Ubuntu映像中。您首先需要安装它。尝试apt-get install software-properties-common

顺便说一句,您无需在Dockerfile中使用sudo,因为默认情况下命令以root身份运行,除非您使用该USER命令更改为另一个用户。


2
我确实添加pt-get install software-properties-common了第一个RUN pt-get install software-properties-common命令,就像这样,现在我得到了这个错误chopapp.com/#8a4vdsnw
Alexander Solonik

1
这取决于你的Ubuntu版本,它可以是python-software-propertiessoftware-properties-common
user2915097

4
在Ubuntu 16.04上,这想安装46MiB其他数据:/太多,无法执行简单的命令。
cweiske '17

27
python-software-properties和software-properties-common均无效
Jonathan Neufeld

10
只为那些仍然有一些错误的人。我通过将update和install放在同一行来解决了:apt-get update && apt-get install -y software-properties-common。先运行更新然后再安装似乎无效。可能是Docker错误
FedFranz

57

在运行apt-add-repository命令之前添加这些行

RUN apt-get update && \
    apt-get install -y software-properties-common && \
    rm -rf /var/lib/apt/lists/*

2
我必须在第一行添加--fix-missing。
Edhowler

1
有什么意义rm -rf /var/lib/apt/lists/*
jumpnett

rm撤销的影响apt-get update。将包元数据存储在容器层中毫无意义。如果以后要apt-get install添加其他软件包,则apt-get update仍然应该重新进行安装。
Toxaris
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.