本文介绍了为什么不在Dockerfile中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Dockerfile创建一个目录,选择它,然后再列出目录。该目录仍由root拥有。为什么是这样?



这是Dockerfile:

  FROM ubuntu :精确
RUN useradd -d / home / testuser -m -s / bin / bash testuser
运行mkdir -p / var / local / testrunner / logs
VOLUME [/ var / local / testrunner / logs]
运行grep testuser / etc / passwd
运行grep root / etc / passwd
RUN chown -R testuser:testuser / var / local / testrunner / logs
RUN ls -ld / var / local / testrunner / logs

这里是docker build :

 将构建上下文发送到Docker守护程序10.24 kB 
将构建上下文发送到Docker守护程序
步骤0 :FROM ubuntu:precise
---> ab8e2728644c
步骤1:运行useradd -d / home / testuser -m -s / bin / bash testuser
--->使用缓存
---> 640f12671c86
步骤2:运行mkdir -p / var / local / testrunner / logs
--->使用缓存
---> bf7756fd5b1f
步骤3:VOLUME [/ var / local / testrunner / logs]
--->使用缓存
---> 65c73ee76c20
步骤4:运行grep testuser / etc / passwd
--->使用缓存
---> db72fff0b965
步骤5:运行grep root / etc / passwd
--->运行在ebff78df7a9a
root:x:0:0:root:/ root:/ bin / bash
---> ead0ff704a59
删除中间容器ebff78df7a9a
步骤6:RUN chown -R testuser:testuser / var / local / testrunner / logs
--->运行在c925f67b2ab4
---> 253132be935e
删除中间容器c925f67b2ab4
步骤7:运行ls -ld / var / local / testrunner / logs
--->运行在978bc66aa47e
drwxr-xr-x 2根员工4096 Oct 1 15:15 / var / local / testrunner / logs

Docker版本1.2.0,构建fa7b24f



主机运行Ubuntu 12.04,但具有3.13.0-36通用内核。 / p>

解决方案

回答我自己的问题:它被声明为一个卷。如果您取出VOLUME指令,则chown将生效。



此外,如果您在运行chown后声明卷之后的批量设置仍然有效。


My Dockerfile creates a directory, chown's it, and then lists the directory afterwards. The directory is still owned by root. Why is that?

Here is the Dockerfile:

FROM ubuntu:precise
RUN useradd -d /home/testuser -m -s /bin/bash testuser
RUN mkdir -p /var/local/testrunner/logs
VOLUME ["/var/local/testrunner/logs"]
RUN grep testuser /etc/passwd
RUN grep root /etc/passwd
RUN chown -R testuser:testuser /var/local/testrunner/logs
RUN ls -ld /var/local/testrunner/logs

Here is the output from "docker build":

Sending build context to Docker daemon 10.24 kB
Sending build context to Docker daemon
Step 0 : FROM ubuntu:precise
 ---> ab8e2728644c
Step 1 : RUN useradd -d /home/testuser -m -s /bin/bash testuser
 ---> Using cache
 ---> 640f12671c86
Step 2 : RUN mkdir -p /var/local/testrunner/logs
 ---> Using cache
 ---> bf7756fd5b1f
Step 3 : VOLUME ["/var/local/testrunner/logs"]
 ---> Using cache
 ---> 65c73ee76c20
Step 4 : RUN grep testuser /etc/passwd
 ---> Using cache
 ---> db72fff0b965
Step 5 : RUN grep root /etc/passwd
 ---> Running in ebff78df7a9a
root:x:0:0:root:/root:/bin/bash
 ---> ead0ff704a59
Removing intermediate container ebff78df7a9a
Step 6 : RUN chown -R testuser:testuser /var/local/testrunner/logs
 ---> Running in c925f67b2ab4
 ---> 253132be935e
Removing intermediate container c925f67b2ab4
Step 7 : RUN ls -ld /var/local/testrunner/logs
 ---> Running in 978bc66aa47e
drwxr-xr-x 2 root staff 4096 Oct  1 15:15 /var/local/testrunner/logs

Docker version 1.2.0, build fa7b24f

The host runs Ubuntu 12.04, but with a 3.13.0-36-generic kernel.

解决方案

Answering my own question: it's declared to be a volume. If you take out the VOLUME instruction, the chown takes effect.

What's more, if you declare the volume after running chown, the chown settings remain in effect.

这篇关于为什么不在Dockerfile中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 18:04