请选择 进入手机版 | 继续访问电脑版
  • 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

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

[复制链接]
菜鸟教程小白 发表于 2022-8-3 10:13:55 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我在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_USERZOO_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权限授予了当前目录中的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



Best Answer-推荐答案


您的docker-entrypoint.sh不可执行,您需要在Dockerfile中的RUN chmod 755 /docker-entrypoint.sh命令之后添加COPY并重建镜像。

关于docker - 无效的 header 字段值“运行docker镜像时出现oci运行时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40471584/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝0

帖子520893

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap