Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create user in ubuntu docker instead using root

I am creating a custom docker image based on ubuntu (testing:latest). I want to run some unit tests for a meteor 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 a 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

Running whoami shows me that the current user is root. Therefore meteor test is not running, as it shouldn't be used with 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

How can I use another user? Do I have to do that in the dockerfile? Or do I have to add some commands in the yml file?

like image 855
user3142695 Avatar asked Oct 30 '25 05:10

user3142695


1 Answers

You can do it the normal Ubuntu way RUN useradd <username> then USER <username> and run the task.

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.

You can also look at this SO Answer: Switching users inside Docker image to a non-root user

like image 65
flamusdiu Avatar answered Nov 02 '25 16:11

flamusdiu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!