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

Ale*_*nik 64 docker

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

mkdir pgrouted
cd pgrouted
touch Dockerfile
Run Code Online (Sandbox Code Playgroud)

现在我在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]"
Run Code Online (Sandbox Code Playgroud)

整个Dockerfile可以在这里看一眼.

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

docker build -t gautam/pgrouted:v1 .
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

为什么我收到此错误?

小智 84

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

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

  • python-software-properties和software-properties-common都不是有效的 (24认同)
  • 只为那些仍然有一些错误的人。我通过将更新和安装放在同一行上来解决:`apt-get update &amp;&amp; apt-get install -y software-properties-common`。先运行更新然后再安装似乎无效。可能是Docker错误 (5认同)
  • 在ubuntu 16.04上,这需要安装46MiB附加数据:/太多,无法执行简单的命令. (4认同)
  • 我确实添加了`pt-get install software-properties-common`作为第一个`RUN pt-get install software-properties-common`命令,就像这样,现在我收到此错误http://chopapp.com/#8a4vdsnw (2认同)
  • 根据您的 Ubuntu 版本,它可以是 `python-software-properties` 或 `software-properties-common` (2认同)

Apo*_*wal 33

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

RUN apt-get update && \
    apt-get install -y software-properties-common && \
    rm -rf /var/lib/apt/lists/*
Run Code Online (Sandbox Code Playgroud)

  • `rm` 撤销 `apt-get update` 的影响。将包元数据存储在容器层中是没有意义的。如果您稍后想要“apt-get install”其他软件包,则无论如何都应该执行新的“apt-get update”。 (4认同)
  • 我不得不将 --fix-missing 添加到第一行。 (2认同)