[英]Unable to install curl command in kubernetes pod
I am using the below command to install curl in one of the pods:我正在使用以下命令在其中一个 Pod 中安装 curl:
$ apt-get install curl
But , I am getting below error:但是,我收到以下错误:
E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?
When I am trying to remove the file /var/lib/dpkg/lock-frontend当我试图删除文件 /var/lib/dpkg/lock-frontend
$ rm /var/lib/dpkg/lock-frontend
rm: remove write-protected regular empty file '/var/lib/dpkg/lock-frontend'? y
rm: cannot remove '/var/lib/dpkg/lock-frontend': Permission denied
I can't use sudo command also :我也不能使用 sudo 命令:
$ sudo rm /var/lib/dpkg/lock-frontend
bash: sudo: command not found
Please help, as I am new to Kubernetes and Pods.请帮忙,因为我是 Kubernetes 和 Pods 的新手。
First of all this is a anti-pattern.首先,这是一种反模式。 Containers are meant to be stateless and not change after they are deployed.容器是无状态的,部署后不会改变。
The reason why you can't run apt-get
is because you are running your container with an unprivileged user as you can tell by the "$" sign in your command prompt.您无法运行apt-get
的原因是因为您正在使用非特权用户运行容器,正如您可以通过命令提示符中的“$”符号看出的那样。 Also sudo
is not installed and thus not usable.此外sudo
未安装,因此无法使用。
If you really want to have curl in your container you have a couple of options:如果你真的想在你的容器中卷曲,你有几个选择:
curl
at build time rather than at run time扩展您的 docker 镜像,并在构建时而不是在运行时安装curl
curl
from an interactive session as you tried to do (discouraged).以 root 身份运行您的容器并按照您尝试的方式从交互式会话安装curl
(不鼓励)。Example of the first approach, the one I suggest you to use, involves a Dockerfile like the following:第一种方法的示例,我建议您使用的方法,涉及一个 Dockerfile,如下所示:
FROM the-image-name-you-are-currently-using
RUN apt-get update; apt-get install -y curl
You then need to build this new image with (from the same directory where your Dockerfile
is):然后,您需要使用(从Dockerfile
所在的同一目录)构建这个新镜像:
docker build -t your-new-image-name:version .
After you pushed the image to a registry with docker push
you can update your Pod
to use your-new-image-name:version
as image.使用docker push
将映像推送到注册表后,您可以更新Pod
以使用your-new-image-name:version
作为映像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.