【问题标题】:Create user in ubuntu docker instead using root在 ubuntu docker 中创建用户,而不是使用 root
【发布时间】:2017-09-19 07:32:02
【问题描述】:

我正在创建一个基于 ubuntu (testing:latest) 的自定义 docker 镜像。我想为一个流星应用程序运行一些单元测试。

FROM ubuntu:16.04
RUN apt-get update -y && \
    apt-get install -yqq --no-install-recommends apt-transport-https ca-certificates curl nodejs-legacy && \
    apt-get clean && apt-get autoclean && apt-get autoremove && \
    curl https://install.meteor.com/ | sh && \
    meteor npm install eslint eslint-plugin-react && \
    apt-get remove -y apt-transport-https ca-certificates curl && \
    rm -rf /var/lib/apt/lists/*

我正在通过 docker 运行器使用 gitlab CI。所以我的 yml 文件看起来像

stages:
  - test

lint:
  image: testing:latest
  stage: test
  script:
    - /node_modules/.bin/eslint --ext .js --ext .jsx .
  except:
    - master

unit:
  image: testing:latest
  stage: test
  script:
    - whoami
    - meteor test --driver-package=practicalmeteor:mocha-console-runner
  except:
    - master

运行whoami 显示当前用户是root。因此流星测试没有运行,因为它不应该与root一起使用

You are attempting to run Meteor as the 'root' superuser. If you are
developing, this is almost certainly *not* what you want to do and will likely
result in incorrect file permissions. However, if you are running this command
in a build process (CI, etc.), or you are absolutely sure you know what you are
doing, set the METEOR_ALLOW_SUPERUSER environment variable or pass
--allow-superuser to proceed.

Even with METEOR_ALLOW_SUPERUSER or --allow-superuser, permissions in your app
directory will be incorrect if you ever attempt to perform any Meteor tasks as
a normal user. If you need to fix your permissions, run the following command
from the root of your project:

  sudo chown -Rh <username> .meteor/local

如何使用其他用户?我必须在 dockerfile 中这样做吗?还是我必须在yml文件中添加一些命令?

【问题讨论】:

    标签: ubuntu meteor docker gitlab gitlab-ci


    【解决方案1】:

    你可以用普通的Ubuntu方式RUN useradd &lt;username&gt;然后USER &lt;username&gt;运行任务。

    From the Docker.Io Docs

    USER 指令设置运行映像时使用的用户名或 UID,以及在 Dockerfile 中的任何 RUN、CMD 和 ENTRYPOINT 指令。

    你也可以看看这个 SO Answer:Switching users inside Docker image to a non-root user

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-16
      • 2018-08-07
      • 2020-07-28
      • 1970-01-01
      • 2021-10-10
      • 1970-01-01
      • 2023-03-03
      • 2019-07-01
      相关资源
      最近更新 更多