83

I have the below Dockerfile for zookeeper and I am trying to create an image for it, but it is giving me an error. I have recently started working with Docker, and started playing with a Zookeeper setup, so I am not able to understand. 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?

5
  • 54
    apk is the package manager for Alpine. You're using Ubuntu. You need to use apt-get.
    – larsks
    Commented Nov 6, 2016 at 2:32
  • 3
    This looks like an article that might be very apropos to what you're trying to do.
    – larsks
    Commented Nov 6, 2016 at 2:34
  • 1
    @larsks thanks for pointing out the mistake. So you are saying I should replace apk with apt-get in my Dockerfile and it should work? I want to keep my FROM tag as it is.
    – john
    Commented Nov 6, 2016 at 3:36
  • I want to use trusty image to make it work.
    – john
    Commented Nov 6, 2016 at 3:41
  • for Alpine users RUN apk update works but RUN "apk update" does not...
    – Ray Foss
    Commented Mar 11, 2021 at 5:22

3 Answers 3

84

As larsks mentions, apk is for Alpine distributions and you selected FROM ubuntu:trusty which is Debian based with the apt-get command. Change your FROM line to FROM alpine:3.4 to switch to the Alpine based image with apk support.

6
  • 3
    aahh now I understood. But let's say I want to keep FROM ubuntu:trusty line then what I need to change? So I should replace apk with apt-get everywhere in my Dockerfile to make it work?
    – john
    Commented Nov 6, 2016 at 3:35
  • 1
    Changing to a different packaging tool that's pointing to it's own repositories means a different syntax and different package names. larsks's second link provides the answer for that.
    – BMitch
    Commented Nov 6, 2016 at 16:24
  • is it possible to install apk manager on ubuntu?
    – user732456
    Commented Jan 4, 2021 at 16:16
  • 1
    @user732456 that would have the same effect as installing Windows 95 and NT on the same C drive. These are different distributions, different (incompatible) libraries, what would happen when one package manager overwrites the files installed by the other?
    – BMitch
    Commented Jan 5, 2021 at 13:23
  • I can imagine that it's not a brilliant idea, but I needed for testing purposes only. Also once I gave my Mac to our admin for installation and if I recall it right I ended up with apt-get on my computer alongside with brew. So my guess was that although it's not a good practice it's not impossible.
    – user732456
    Commented Jan 5, 2021 at 14:29
24

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:

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

Otherwise Alpine base image can be used to run apk commands:

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

Hmm I don't see this case but I'm using Docker with an ubuntu:22.04 base image and what actually works is apt (without -get) as in:

RUN apt install util-linux

3
  • How does your answer differ from the others?
    – Nico Haase
    Commented Jun 26 at 9:18
  • @NicoHaase I don't see apt mentioned anywhere - correct me if I'm wrong Commented Jun 26 at 9:20
  • Using apt instead of apt-get might be a small detail, but are you sure that it is so important that it deserves a new answer on an eight years old question, especially if your preconditions are different?
    – Nico Haase
    Commented Jun 26 at 9:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.