无效的头字段值“运行docker镜像时出现oci运行时错误

前端之家收集整理的这篇文章主要介绍了无效的头字段值“运行docker镜像时出现oci运行时错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我有以下Dockerfile用于zookeeper安装,我为此建立了docker镜像.

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

我像这样构建它:

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

当我运行zookeeper实例时,我收到此错误

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".

这有什么不对?我在zookeeper-docker目录下有我的所有文件.我还将chmod x persmission给了当前目录中的docker-entrypoint.sh.

以下是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 "$@"

以下是输出

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
您的docker-entrypoint.sh不可执行,您需要在Dockerfile中的COPY命令之后添加RUN chmod 755 /docker-entrypoint.sh并重建映像.
原文链接:https://www.f2er.com/docker/436523.html

猜你在找的Docker相关文章