无法以非root用户身份解压缩DockerFile中的zip文件 [英] Cannot unzip zip file in DockerFile as non root user

查看:52
本文介绍了无法以非root用户身份解压缩DockerFile中的zip文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在DockerFile中解压缩zip文件时,我不断收到以下错误消息

I keep getting the below error when I try to unzip a zip file in my DockerFile

checkdir error:  cannot create my-archive
                 Permission denied
                 unable to process my-archive/data/sample.jar
The command '/bin/sh -c unzip /home/kong/my-archive.zip' returned a non-zero code: 2

在我的DockerFile中,我有:

In my DockerFile I have:

RUN useradd -ms /bin/bash kong
RUN echo "kong:password" | chpasswd
RUN adduser kong sudo
USER kong
RUN wget "${url}/my-archive.zip" -P /home/kong
RUN unzip /home/kong/my-archive.zip

如果我这样做,它会起作用:

It works if I do:

USER root
RUN unzip /home/kong/my-archive.zip

但我希望能够以非root用户身份执行此操作.

but I would like to be able to do this as a non root user.

为什么非root用户 kong 失败?

Why does it fail as non root user kong?

推荐答案

您似乎正在尝试将归档文件解压缩到/文件夹中.

It looks like you are trying to unzip the archive in the / folder.

实际上,默认情况下, unzip 命令将存档解压缩到当前目录中.

In fact, the unzip command unzips the archive by default in the current directory.

此外,该zip文件是作为root用户下载的,kong用户可能无法读取.

Plus, the zip file is downloaded as root and might not be readable by the kong user.

尝试如下更改您的Dockerfile:

Try changing your Dockerfile as follows:

RUN useradd -ms /bin/bash kong
RUN echo "kong:password" | chpasswd
RUN adduser kong sudo
USER kong
WORKDIR /home/kong
RUN wget "${url}/my-archive.zip" -P /home/kong
RUN unzip /home/kong/my-archive.zip

这样,.zip文件将归kong用户所有,您将其解压缩到其主目录中.

This way, the .zip file will be owned by the kong user and you will unzip it in his home directory.

这篇关于无法以非root用户身份解压缩DockerFile中的zip文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆