Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Variables in Dockerfile don't seem to be recognized?

I am building an image using Dockfile. I would like to set the Username of the container via the command line to avoid permission issues.

The Dockfile is shown below, I used the variables of USER_NAME, GROUP_ID. But when I build, the problem keeps appearing.
The error is: groupadd: option '--gid' requires an argument
I’m guessing that both ${GROUP_ID} and ${USER_NAME} are recognized as empty strings, but shouldn’t they be assigned values ​​when the container is created?
I’ve googled a few examples and based on the examples, I don’t quite see where the problem is?

Please help me!
Thanks!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

FROM matthewfeickert/docker-python3-ubuntu:latest
ARG USER_NAME
ARG USER_ID
ARG GROUP_ID


RUN groupadd -r --gid ${GROUP_ID} ${USER_NAME} 
RUN useradd --no-log-init -r -g ${GROUP_ID} -u ${USER_ID} ${USER_NAME}

USER ${USER_NAME}
WORKDIR /usr/local/src

>Solution :

You can pass the build args as shown below.

docker build --build-arg USER_NAME=test --build-arg USER_ID=805 --build-arg GROUP_ID=805 -t tag1 .

Also, as a best practice consider adding default vales to the args. So if the user doesn’t specify the args the default values will be picked.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading