invalid header field value "oci runtime error while running docker image
Asked Answered
D

1

6

I have below Dockerfile for zookeeper setup and I have built docker image for that.

FROM openjdk:8-jre-alpine

# 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"]

I build it like this:

root@duo4:/home/david/zookeeper-docker# docker build -t david/zookeeper:3.4.9 .

When I run the zookeeper instance, I am getting this error:

root@duo4:/home/david/zookeeper-docker# docker run --name zookeeper --restart always -d david/zookeeper:3.4.9
24a282f2d04f1b638820a63a2037f618621d315d8c1cdb62aed609426bb19045
docker: Error response from daemon: invalid header field value "oci runtime error: container_linux.go:247: starting container process caused \"exec: \\\"/docker-entrypoint.sh\\\": permission denied\"\n".

What is wrong here? I have all my files inside zookeeper-docker directory. Also I gave chmod +x persmission to docker-entrypoint.sh in my current directory.

Below is the content of docker-entrypoint.sh

#!/bin/bash

set -e

# Allow the container to be started with `--user`
if [ "$1" = 'zkServer.sh' -a "$(id -u)" = '0' ]; then
    chown -R "$ZOO_USER" "$ZOO_DATA_DIR" "$ZOO_DATA_LOG_DIR"
    exec su-exec "$ZOO_USER" "$0" "$@"
fi

# Generate the config only if it doesn't exist
if [ ! -f "$ZOO_CONF_DIR/zoo.cfg" ]; then
    CONFIG="$ZOO_CONF_DIR/zoo.cfg"

    echo "clientPort=$ZOO_PORT" >> "$CONFIG"
    echo "dataDir=$ZOO_DATA_DIR" >> "$CONFIG"
    echo "dataLogDir=$ZOO_DATA_LOG_DIR" >> "$CONFIG"

    echo "tickTime=$ZOO_TICK_TIME" >> "$CONFIG"
    echo "initLimit=$ZOO_INIT_LIMIT" >> "$CONFIG"
    echo "syncLimit=$ZOO_SYNC_LIMIT" >> "$CONFIG"

    for server in $ZOO_SERVERS; do
        echo "$server" >> "$CONFIG"
    done
fi

# Write myid only if it doesn't exist
if [ ! -f "$ZOO_DATA_DIR/myid" ]; then
    echo "${ZOO_MY_ID:-1}" > "$ZOO_DATA_DIR/myid"
fi

exec "$@"

Below is the output:

root@duo4:/home/david/zookeeper-docker# docker run --name zookeeper --entrypoint "/usr/bin/env" david/zookeeper:3.4.9 -- ls -al /
total 80
drwxr-xr-x   47 root     root          4096 Nov  7 19:09 .
drwxr-xr-x   47 root     root          4096 Nov  7 19:09 ..
-rwxr-xr-x    1 root     root             0 Nov  7 19:09 .dockerenv
drwxr-xr-x    2 root     root          4096 Nov  7 17:44 bin
drwxr-xr-x    2 zookeepe zookeepe      4096 Nov  7 17:45 conf
drwxr-xr-x    2 zookeepe zookeepe      4096 Nov  7 19:09 data
drwxr-xr-x    2 zookeepe zookeepe      4096 Nov  7 19:09 datalog
drwxr-xr-x    5 root     root           360 Nov  7 19:09 dev
-rw-r--r--    1 root     root           873 Nov  6 01:36 docker-entrypoint.sh
drwxr-xr-x   22 root     root          4096 Nov  7 19:09 etc
drwxr-xr-x    3 root     root          4096 Nov  7 17:44 home
drwxr-xr-x    8 root     root          4096 Nov  7 17:45 lib
lrwxrwxrwx    1 root     root            12 Oct 18 18:58 linuxrc -> /bin/busybox
drwxr-xr-x    5 root     root          4096 Oct 18 18:58 media
drwxr-xr-x    2 root     root          4096 Oct 18 18:58 mnt
dr-xr-xr-x  141 root     root             0 Nov  7 19:09 proc
drwx------    2 root     root          4096 Oct 18 18:58 root
drwxr-xr-x    2 root     root          4096 Oct 18 18:58 run
drwxr-xr-x    2 root     root          4096 Nov  7 17:44 sbin
drwxr-xr-x    2 root     root          4096 Oct 18 18:58 srv
dr-xr-xr-x   13 root     root             0 Nov  7 19:09 sys
drwxrwxrwt    2 root     root          4096 Nov  7 17:45 tmp
drwxr-xr-x   19 root     root          4096 Nov  7 17:45 usr
drwxr-xr-x   15 root     root          4096 Nov  7 17:44 var
drwxr-xr-x   10 1001     1001          4096 Nov  7 17:45 zookeeper-3.4.9
Document answered 7/11, 2016 at 18:0 Comment(6)
What's inside docker-entrypoint.sh?Adagietto
I have updated in the question.Document
I have updated again. let me know if that's what you meant. I am relatively new to Docker so let me know if I am not doing anything right.Document
I guess @BMitch meant docker run --name zookeeper --entrypoint "/bin/env" david/zookeeper:3.4.9 -- ls -al / not with /entrypoint at the end??Mafalda
Derp, 3rd time is the charm? docker run --name zookeeper --entrypoint "/usr/bin/env" david/zookeeper:3.4.9 -- ls -al /docker-entrypoint.shStuppy
Ok updated again.Document
S
16

Your docker-entrypoint.sh isn't executable, you need to add a RUN chmod 755 /docker-entrypoint.sh after the COPY command in your Dockerfile and rebuild the image.

Stuppy answered 7/11, 2016 at 19:12 Comment(6)
Ok got it so should I delete the image and built it again. Or is there any other command which can rebuilt it without deleting it?Document
No need to delete. If you rebuild with the same tag, it will overwrite the previous tag. And when rebuilding regardless of the tag, if it sees the same command/image combination, it will reuse that intermediate image, making rebuilds very fast if your changes are at the end of the Dockerfile. You may want to cleanup orphaned layers after doing this for a while to conserve disk space.Stuppy
docker images -qf dangling=true --no-trunc | xargs --no-run-if-empty docker rmi is my preferred cleanup command.Stuppy
thanks for your help. This time what I ran my docker image after rebuilding it, I didn't got any error at all. It just printed me some big string mix of numbers and strings. So looks like my zookeeper got started up. Now is there any way I can check whether my zookeeper is running in the container just to make sure?Document
With detached (-d), you're just getting the container id back. docker exec -it zookeeper /bin/sh will give you a prompt in the container. From there you should be able to run commands like ps -ef to see the process running. You can also run docker logs zookeeper to see the output of the container.Stuppy
awesome thanks a lot. learned quite a bit of things today. appreciated your help.Document

© 2022 - 2024 — McMap. All rights reserved.