[英]/bin/sh: 1: apk: not found while creating docker image
I have the below Dockerfile for zookeeper and I am trying to create an image for it, but it is giving me an error.我有以下用于 zookeeper 的 Dockerfile,我正在尝试为它创建一个图像,但它给了我一个错误。 I have recently started working with Docker, and started playing with a Zookeeper setup, so I am not able to understand.
我最近开始使用 Docker,并开始使用 Zookeeper 设置,所以我无法理解。 What does this error mean?
这个错误是什么意思?
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"]
Below is the error I got:下面是我得到的错误:
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
Am I doing anything wrong here?我在这里做错了什么吗? Why is
apk
not found?为什么找不到
apk
?
As larsks mentions , apk
is for Alpine distributions and you selected FROM ubuntu:trusty
which is Debian based with the apt-get
command.正如larsks 提到的,
apk
适用于 Alpine 发行版,您选择了FROM ubuntu:trusty
trusty ,它是基于 Debian 的apt-get
命令。 Change your FROM line to FROM alpine:3.4
to switch to the Alpine based image with apk
support.将您的 FROM 行更改为
FROM alpine:3.4
以切换到具有apk
支持的基于 Alpine 的图像。
Quite late to the party.聚会很晚了。 I'll put down what worked for me.
我会记下对我有用的东西。
As john rightly pointed out that apk is package manager for alpine distributions, for ubuntu image, we need to use apt-get:正如john正确指出的,apk 是 alpine 发行版的包管理器,对于 ubuntu 镜像,我们需要使用 apt-get:
FROM ubuntu:trusty
RUN apt-get update && apt-get install -y tini
Otherwise Alpine base image can be used to run apk commands:否则 Alpine 基础镜像可用于运行 apk 命令:
FROM python:3.7-alpine3.12
RUN apk add --no-cache tini
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.