在ubuntu docker中创建用户,而不是使用root

在ubuntu docker中创建用户,而不是使用root,ubuntu,meteor,docker,gitlab,gitlab-ci,Ubuntu,Meteor,Docker,Gitlab,Gitlab Ci,我正在基于ubuntu创建一个自定义docker映像(testing:latest)。我想为meteor应用程序运行一些单元测试 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 cle

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

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/*
我使用的是gitlab CI,使用的是dockerrunner。所以我的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
。因此meteor测试没有运行,因为它不应该与
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
您正试图以“root”超级用户身份运行Meteor。如果你是
发展中,这几乎肯定不是你想做的,也很可能是你想做的
导致文件权限不正确。但是,如果您正在运行此命令
在构建过程中(CI等),或者您完全确定自己知道自己是什么
执行此操作时,请设置METEOR_ALLOW_SUPERUSER环境变量或pass
--允许超级用户继续。
即使使用METEOR_ALLOW_SUPERUSER或--ALLOW SUPERUSER,应用程序中的权限也是如此
如果您试图执行任何流星任务,则目录将不正确
普通用户。如果需要修复权限,请运行以下命令
从项目的根目录:
sudo chown-右侧流星/本地

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

你可以用Ubuntu的正常方式运行useradd,然后运行任务

USER
指令设置运行映像时要使用的用户名或UID,以及
Dockerfile
中紧随其后的任何
RUN
CMD
ENTRYPOINT
指令

你也可以看看这个答案: