使用root在ubuntu docker中创建用户

时间:2017-04-22 08:54:24

标签: ubuntu meteor docker gitlab gitlab-ci

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

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文件中添加一些命令?

1 个答案:

答案 0 :(得分:3)

您可以使用正常的Ubuntu方式RUN useradd <username>然后USER <username>来执行此任务。

From the Docker.Io Docs

  

USER指令设置运行图片时要使用的用户名或UID,以及RUNCMDENTRYPOINT后面的说明。 1}}。

您还可以查看此SO答案:Switching users inside Docker image to a non-root user