apt-add-repository: lỗi không tìm thấy lệnh trong Dockerfile


92

Tôi vừa tạo một tệp Docker rất đơn giản trong thiết bị đầu cuối của mình, về cơ bản tôi đã làm như sau:

mkdir pgrouted
cd pgrouted
touch Dockerfile

Bây giờ tôi mở tệp Docker trong trình chỉnh sửa nano và thêm các lệnh sau vào tệp 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]"

Toàn bộ Dockerfile có thể được xem ngay TẠI ĐÂY .

Bây giờ khi tôi cố gắng xây dựng Dockerfile, như sau:

docker build -t gautam/pgrouted:v1 .

Dockerfile chạy và sau đó tôi gặp lỗi dưới đây:

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

Tại sao tôi gặp lỗi này?

Câu trả lời:


121

apt-add-repository không có trong hình ảnh Ubuntu cơ sở. Trước tiên, bạn cần cài đặt nó. thửapt-get install software-properties-common

Nhân tiện, bạn không cần sử dụng sudo trong Dockerfile vì các lệnh chạy dưới dạng root theo mặc định trừ khi bạn thay đổi thành người dùng khác bằng USERlệnh.


2
tôi đã thêm pt-get install software-properties-commonnhư là người đầu tiên RUN pt-get install software-properties-commonlệnh, như vậy, bây giờ tôi nhận được lỗi này chopapp.com/#8a4vdsnw
Alexander Solonik

1
tùy thuộc vào phiên bản Ubuntu của bạn, nó có thể là python-software-propertieshoặcsoftware-properties-common
user2915097 09/09

4
trên ubuntu 16.04, điều này muốn cài đặt thêm dữ liệu 46MiB: / quá nhiều để có thể thực hiện một lệnh đơn giản.
cweiske

27
Cả python-phần mềm-tính hay phần mềm tính-chung có giá trị
Jonathan Neufeld

10
Chỉ dành cho những người vẫn gặp một số lỗi. Tôi đã giải quyết bằng cách đặt bản cập nhật và cài đặt trên cùng một dòng: apt-get update && apt-get install -y software-properties-common. Chạy bản cập nhật đầu tiên và sau đó cài đặt dường như không hoạt động. Có thể là lỗi Docker
FedFranz 19/10/18

57

Thêm các dòng này trước khi chạy apt-add-repositorylệnh

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

2
Tôi phải thêm - thiếu tiền tố vào dòng đầu tiên.
Edhowler

1
Mục đích là rm -rf /var/lib/apt/lists/*gì?
jumpnett

Các rmtác động của apt-get update. Không có ích lợi gì khi lưu trữ siêu dữ liệu gói trong lớp vùng chứa. Nếu sau này bạn muốn apt-get installbổ sung các gói, bạn nên làm một gói mới apt-get update.
Toxaris
Khi sử dụng trang web của chúng tôi, bạn xác nhận rằng bạn đã đọc và hiểu Chính sách cookieChính sách bảo mật của chúng tôi.
Licensed under cc by-sa 3.0 with attribution required.