Docker-安装目录的所有者和组

问题描述 投票:0回答:1

我运行了一个将主机目录绑定到容器目录的docker容器,但是根据主机的不同,容器目录及其文件的权限也会有所不同。

docker run -w /vlc-android -v $(pwd)/vlc-android:/vlc-android --rm vlc-android:latest bash -c "ls -ld /vlc-android"

在Mac OS 10.14.6(Docker桌面版本2.1.0.3上的结果)

drwxr-xr-x 2 videolan videolan 64 Sep 27 04:34 / vlc-android

在Ubuntu服务器18.04.3上的结果

drwxr-xr-x 2 root root 4096 Sep 27 06:11 / vlc-android

我正在尝试构建VLC播放器android应用。从source codedocker image of the vlc-android build environment或以下...

FROM debian:stretch-20190506

MAINTAINER VideoLAN roots <[email protected]>

ENV IMAGE_DATE=201907171600

ENV ANDROID_NDK="/sdk/android-ndk" \
    ANDROID_SDK="/sdk/android-sdk-linux"

# If someone wants to use VideoLAN docker images on a local machine and does
# not want to be disturbed by the videolan user, we should not take an uid/gid
# in the user range of main distributions, which means:
# - Debian based: <1000
# - RPM based: <500 (CentOS, RedHat, etc.)
ARG VIDEOLAN_CI_UID=499

RUN addgroup --quiet --gid ${VIDEOLAN_CI_UID} videolan && \
    adduser --quiet --uid ${VIDEOLAN_CI_UID} --ingroup videolan videolan && \
    echo "videolan:videolan" | chpasswd && \
    apt-get update && \
    apt-get install --no-install-suggests --no-install-recommends -y \
    openjdk-8-jdk-headless ca-certificates autoconf m4 automake ant autopoint bison \
    flex build-essential libtool libtool-bin patch pkg-config ragel subversion \
    git rpm2cpio libwebkitgtk-1.0-0 yasm ragel g++ protobuf-compiler gettext \
    libgsm1-dev wget expect unzip python python3 locales libltdl-dev curl && \
    echo "deb http://ftp.debian.org/debian stretch-backports main" > /etc/apt/sources.list.d/stretch-backports.list && \
    apt-get update && apt-get -y -t stretch-backports install cmake && \
    rm -f /etc/apt/sources.list.d/stretch-backports.list && \
    echo "deb http://deb.debian.org/debian testing main" > /etc/apt/sources.list.d/testing.list && \
    apt-get update && apt-get -y -t testing --no-install-suggests --no-install-recommends install automake && \
    rm -f /etc/apt/sources.list.d/testing.list && \
    apt-get clean -y && rm -rf /var/lib/apt/lists/* && \
    localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 && \
    echo "export ANDROID_NDK=${ANDROID_NDK}" >> /etc/profile.d/vlc_env.sh && \
    echo "export ANDROID_SDK=${ANDROID_SDK}" >> /etc/profile.d/vlc_env.sh && \
    mkdir sdk && cd sdk && \
    wget -q https://dl.google.com/android/repository/android-ndk-r18b-linux-x86_64.zip && \
    ANDROID_NDK_SHA256=4f61cbe4bbf6406aa5ef2ae871def78010eed6271af72de83f8bd0b07a9fd3fd && \
    echo $ANDROID_NDK_SHA256 android-ndk-r18b-linux-x86_64.zip | sha256sum -c && \
    unzip android-ndk-r18b-linux-x86_64.zip && \
    rm -f android-ndk-r18b-linux-x86_64.zip && \
    ln -s android-ndk-r18b android-ndk && \
    mkdir android-sdk-linux && \
    cd android-sdk-linux && \
    mkdir "licenses" && \
    echo "24333f8a63b6825ea9c5514f83c2829b004d1fee" > "licenses/android-sdk-license" && \
    echo "d56f5187479451eabf01fb78af6dfcb131a6481e" >> "licenses/android-sdk-license" && \
    wget -q https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip && \
    SDK_TOOLS_SHA256=444e22ce8ca0f67353bda4b85175ed3731cae3ffa695ca18119cbacef1c1bea0 && \
    echo $SDK_TOOLS_SHA256 sdk-tools-linux-3859397.zip | sha256sum -c && \
    unzip sdk-tools-linux-3859397.zip && \
    rm -f sdk-tools-linux-3859397.zip && \
    tools/bin/sdkmanager "build-tools;26.0.1" "platform-tools" "platforms;android-26" && \
    chown -R videolan /sdk

ENV LANG en_US.UTF-8
USER videolan

RUN git config --global user.name "VLC Android" && \
    git config --global user.email [email protected]

并且像下面这样构建

docker build -t vlc-android .

我希望用户ID“ videolan”是容器目录“ / vlc-android”的所有者ID,并且该容器下的所有文件都在Ubuntu服务器18.04.3上运行,例如“在Mac OS 10.14.6( Docker桌面版本2.1.0.3)“。

我该怎么办?

docker permissions vlc docker-volume vlc-android
1个回答
0
投票

[在Linux上安装卷时,泊坞窗容器中的结果文件夹将获得与主机上的文件夹相同的权限。如果主机上的文件夹由root拥有,则它还将在docker容器内也由root拥有。

[要解决您的问题,您必须更改$(pwd)/vlc-android的所有者以匹配容器中使用的用户ID(根据您在问题中附加的Dockerfile,UID为499)。

尝试执行此操作:

sudo chown 499 -R $(pwd)/vlc-android

然后重新启动容器。

© www.soinside.com 2019 - 2024. All rights reserved.