/ bin / sh:1:apk:创建docker镜像时找不到

时间:2016-11-06 01:49:33

标签: ubuntu docker dockerfile apt

我有以下用于zookeeper的Dockerfile,我正在尝试为它创建一个图像,但它给了我一个错误。我最近开始使用Docker,并开始使用Zookeeper设置,所以我无法理解。这个错误意味着什么?

library(data.table)
setDT(DF)[CJ(id = id, st.name = st.name, unique=TRUE), on=.(id, st.name)]

以下是我得到的错误:

FROM ubuntu:trusty
MAINTAINER David

RUN apt-get update && apt-get install -y openjdk-7-jre-headless wget
ENV JAVA_HOME /usr/lib/jvm/java-7-openjdk-amd64

# Install required packages
RUN apk add --no-cache \
    bash \
    su-exec

ENV ZOO_USER=zookeeper \
    ZOO_CONF_DIR=/conf \
    ZOO_DATA_DIR=/data \
    ZOO_DATA_LOG_DIR=/datalog \
    ZOO_PORT=2181 \
    ZOO_TICK_TIME=2000 \
    ZOO_INIT_LIMIT=5 \
    ZOO_SYNC_LIMIT=2

# Add a user and make dirs
RUN set -x \
    && adduser -D "$ZOO_USER" \
    && mkdir -p "$ZOO_DATA_LOG_DIR" "$ZOO_DATA_DIR" "$ZOO_CONF_DIR" \
    && chown "$ZOO_USER:$ZOO_USER" "$ZOO_DATA_LOG_DIR" "$ZOO_DATA_DIR" "$ZOO_CONF_DIR"

ARG GPG_KEY=C823E3E5B12AF29C67F81976F5CECB3CB5E9BD2D
ARG DISTRO_NAME=zookeeper-3.4.9

# Download Apache Zookeeper, verify its PGP signature, untar and clean up
RUN set -x \
    && apk add --no-cache --virtual .build-deps \
        gnupg \
    && wget -q "http://www.apache.org/dist/zookeeper/$DISTRO_NAME/$DISTRO_NAME.tar.gz" \
    && wget -q "http://www.apache.org/dist/zookeeper/$DISTRO_NAME/$DISTRO_NAME.tar.gz.asc" \
    && export GNUPGHOME="$(mktemp -d)" \
    && gpg --keyserver ha.pool.sks-keyservers.net --recv-key "$GPG_KEY" \
    && gpg --batch --verify "$DISTRO_NAME.tar.gz.asc" "$DISTRO_NAME.tar.gz" \
    && tar -xzf "$DISTRO_NAME.tar.gz" \
    && mv "$DISTRO_NAME/conf/"* "$ZOO_CONF_DIR" \
    && rm -r "$GNUPGHOME" "$DISTRO_NAME.tar.gz" "$DISTRO_NAME.tar.gz.asc" \
    && apk del .build-deps

WORKDIR $DISTRO_NAME
VOLUME ["$ZOO_DATA_DIR", "$ZOO_DATA_LOG_DIR"]

EXPOSE $ZOO_PORT 2888 3888

ENV PATH=$PATH:/$DISTRO_NAME/bin \
    ZOOCFGDIR=$ZOO_CONF_DIR

COPY docker-entrypoint.sh /
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["zkServer.sh", "start-foreground"]

我在这里做错了吗?为什么找不到Step 4 : ENV JAVA_HOME /usr/lib/jvm/java-7-openjdk-amd64 ---> Running in a49507cb9725 ---> 77b37883caf4 Removing intermediate container a49507cb9725 Step 5 : RUN apk add --no-cache bash su-exec ---> Running in a4fd76a644cf /bin/sh: 1: apk: not found The command '/bin/sh -c apk add --no-cache bash su-exec' returned a non-zero code: 127

2 个答案:

答案 0 :(得分:13)

作为larsks mentionsapk适用于Alpine发行版,您使用FROM ubuntu:trusty命令选择了基于Debian的apt-get。将您的FROM行更改为FROM alpine:3.4,以切换到支持apk的基于Alpine的图片。

答案 1 :(得分:3)

聚会太晚了。我会放下对我有用的东西。

正如john正确指出apk是alpine发行版的包管理器,对于ubuntu镜像,我们需要使用apt-get:

FROM ubuntu:trusty
RUN apt-get update && apt-get install -y tini

否则 Alpine 基础镜像可用于运行 apk 命令:

FROM python:3.7-alpine3.12
RUN apk add --no-cache tini