简体   繁体   English

运行Docker容器时出错

[英]Error while running docker container

I am running a docker image using the following command. 我正在使用以下命令运行docker映像。

docker run -it -p 8080:8080 -p 29418:29418 --rm \  
-e AUTH_TYPE='DEVELOPMENT_BECOME_ANY_ACCOUNT' \
-v /home/gerrit-site:/home/gerrit/site \
-v /home/nidhi/.ssh/id_rsa.pub:/root/.ssh/id_admin_rsa.pub \
-v /home/nidhi/.ssh/id_rsa:/root/.ssh/id_admin_rsa \
-e GERRIT_ADMIN_USER='admin' \
-e GERRIT_ADMIN_EMAIL='admin@fabric8.io' \
-e GERRIT_ADMIN_FULLNAME='Administrator' \
-e GERRIT_ADMIN_PWD='mysecret' \          
-e GERRIT_ADMIN_PRIVATE_KEY='/home/gerrit/ssh-keys/id_admin_rsa' \
-e GERRIT_PUBLIC_KEYS_PATH='/home/gerrit/ssh-keys' \
-v /home/nidhi/.ssh:/home/gerrit/ssh-keys \
--name gerrit admin_gerrit

I know the command is right cause I had used this command before and it worked perfectly fine. 我知道该命令是正确的,因为我之前曾使用过此命令,并且效果很好。 But now, when I run this command I get the following error, 但是现在,当我运行此命令时,出现以下错误,

Error response from daemon: Cannot start container 2c9514c3b0d953344e66525d083c7ec3921cb9cde2185f43ec3bec2579597485: stat /home/nidhi/.ssh/id_rsa: permission denied

I checked the permission for the ssh public and private keys. 我检查了ssh公钥和私钥的许可。 The permission is 700 and is owned by nidhi. 许可为700,由nidhi拥有。 Please can someone point out what my error is. 请有人指出我的错误是什么。

When docker runs, the uid in your container will likely not match the uid on the host. 当docker运行时,您容器中的uid可能与主机上的uid不匹配。 So with a host volume containing files with 700 permissions, that will not be readable by the uid inside the container. 因此,对于包含具有700个权限的文件的主机卷,容器内的uid将无法读取该卷。 Three options come to mind: 我想到了三个选择:

  1. To keep the 700 permissions and same image, you'd need to chown the file on the host to match the uid inside the container. 为了保持700个权限和相同的图像,您需要将主机上的文件扔掉以匹配容器内的uid。
  2. You can use a named volume instead of a host volume, add your credentials to that named volume, and then set permissions inside there to match the containers where you'll use the volume. 您可以使用命名卷而不是主机卷,将凭据添加到该命名卷,然后在其中设置权限以匹配将使用该卷的容器。
  3. Or you can use a different image that's been rebuilt to change the uid to match your own on the host. 或者,您可以使用已重建的其他映像来更改uid以使其与主机上的uid匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM