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

前端之家收集整理的这篇文章主要介绍了在ubuntu docker中创建用户而不是使用root 前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

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

我正在使用dockerrunner使用gitlab CI.所以我的yml文件看起来像

  1. stages:
  2. - test
  3. lint:
  4. image: testing:latest
  5. stage: test
  6. script:
  7. - /node_modules/.bin/eslint --ext .js --ext .jsx .
  8. except:
  9. - master
  10. unit:
  11. image: testing:latest
  12. stage: test
  13. script:
  14. - whoami
  15. - meteor test --driver-package=practicalmeteor:mocha-console-runner
  16. except:
  17. - master

运行whoami向我显示当前用户是root.因此流星测试未在运行,因为它不应与root一起使用

  1. You are attempting to run Meteor as the 'root' superuser. If you are
  2. developing,this is almost certainly *not* what you want to do and will likely
  3. result in incorrect file permissions. However,if you are running this command
  4. in a build process (CI,etc.),or you are absolutely sure you know what you are
  5. doing,set the METEOR_ALLOW_SUPERUSER environment variable or pass
  6. --allow-superuser to proceed.
  7. Even with METEOR_ALLOW_SUPERUSER or --allow-superuser,permissions in your app
  8. directory will be incorrect if you ever attempt to perform any Meteor tasks as
  9. a normal user. If you need to fix your permissions,run the following command
  10. from the root of your project:
  11. sudo chown -Rh <username> .meteor/local

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

最佳答案
您可以通过普通的Ubuntu方法RUN useradd< username>然后USER<用户名>并运行任务.

From the Docker.Io Docs

The USER instruction sets the user name or UID to use when running the image and for any RUN,CMD and ENTRYPOINT instructions that follow it in the Dockerfile.

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

猜你在找的Docker相关文章