Create a user in ubuntu docker instead with root
I am creating a custom docker image based on ubuntu ( testing:latest
). I want to run some unit tests for meteorite application.
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/*
I am using gitlab CI using docker runner . So my yml file looks like
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
Startup whoami
shows the current user root
. Therefore the meteor test does not work as it cannot be used withroot
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
How can I use another user? Should I be doing this in a docker file? Or do I need to add some commands to the yml file?
source to share
You can do this in the usual Ubuntu way RUN useradd <username>
, then USER <username>
run the task.
Instruction
USER
sets the user name or UID to be used for start-up and image for any instructionRUN
,CMD
andENTRYPOINT
who follow himDockerfile
.
You can also look at this SO answer: Switching users inside a Docker image to a non-root user
source to share