Reference to configuration properties - uid in docker container

Hi,

is there a complete reference for all nexus OSS configuration properties?

How can I change the uid nexus OSS is running as in a container? (like not 200?)

thank you
best regards
Torsten

You can find the code that generates the nexus3 docker image at GitHub - sonatype/docker-nexus3: Dockerized version of Nexus Repo Manager 3. I’m not sure how the uid gets set actually, but it’s not part of the Nexus Repository itself, but rather a part of how the docker image gets generated. This article seems relevant to your question but I’m not super-familiar with how all this works Understanding how uid and gid work in Docker containers | by Marc Campbell | Medium.

Thank you your reply, I had a look into it.
I cloned the master branch of

Here the User used (nexus with uid 200) is not set up by docker and its configs.

The uid of the nexus user is set in the chef-solo cookbook which used to install nexus OSS while building the container.

The chef-solo command used in the Dockerfile of the build fetches a cookbook tarball from github configured as follows:

ARG NEXUS_REPOSITORY_MANAGER_COOKBOOK_VERSION=ā€œrelease-0.5.20210628-162332.70a6cb6ā€
ARG NEXUS_REPOSITORY_MANAGER_COOKBOOK_URL=ā€œhttps://github.com/sonatype/chef-nexus-repository-manager/releases/download/${NEXUS_REPOSITORY_MANAGER_COOKBOOK_VERSION}/chef-nexus-repository-manager.tar.gzā€

Unpacking this tarball I find a file:

[…]/cookbooks/nexus_repository_manager/recipes/users.rb

In which the UID 200 is hardcoded…

user ā€˜nexus’ do
uid ā€˜200’
[…]

One may now think let’s just change it an feed a custom cookbooks tarball to the chef-solo command in the Dockerfile.

I unpack the /chef-nexus-repository-manager.tar.gz which unpacks to a folder ā€˜cookbooks’.
I change the uid in the mentioned file to my liking.

pack it again
tar czvf cookbooks.tar.gz cookbooks

Add to Container
ADD ./cookbooks.tar.gz /cookbooks.tar.gz

run chef-solo
[…]
&& chef-solo --recipe-url /cookbooks.tar.gz
–json-attributes /var/chef/solo.json
[…]

this fails with

/opt/chef/embedded/lib/ruby/2.5.0/fileutils.rb:1293:in copy_stream': Is a directory - read (Errno::EISDIR) from /opt/chef/embedded/lib/ruby/2.5.0/fileutils.rb:1293:in block (2 levels) in copy_file’
from /opt/chef/embedded/lib/ruby/2.5.0/fileutils.rb:1292:in open' from /opt/chef/embedded/lib/ruby/2.5.0/fileutils.rb:1292:in block in copy_file’
from /opt/chef/embedded/lib/ruby/2.5.0/fileutils.rb:1291:in open' from /opt/chef/embedded/lib/ruby/2.5.0/fileutils.rb:1291:in copy_file’
from /opt/chef/embedded/lib/ruby/2.5.0/fileutils.rb:432:in copy_file' from /opt/chef/embedded/lib/ruby/2.5.0/fileutils.rb:359:in block in cp’
from /opt/chef/embedded/lib/ruby/2.5.0/fileutils.rb:1463:in block in fu_each_src_dest' from /opt/chef/embedded/lib/ruby/2.5.0/fileutils.rb:1479:in fu_each_src_dest0’
from /opt/chef/embedded/lib/ruby/2.5.0/fileutils.rb:1461:in fu_each_src_dest' from /opt/chef/embedded/lib/ruby/2.5.0/fileutils.rb:358:in cp’
from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.12.9/lib/chef/application/client.rb:547:in fetch_recipe_tarball' from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.12.9/lib/chef/application/client.rb:350:in reconfigure’
from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.12.9/lib/chef/application.rb:64:in run' from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.12.9/lib/chef/application/solo.rb:230:in run’
from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.12.9/bin/chef-solo:24:in <top (required)>' from /usr/bin/chef-solo:75:in load’
from /usr/bin/chef-solo:75:in `’

Well. If somebody is familiar with chef-solo and its whereabouts and has an idea how to solve this, I’d be very thankful for any hints.

Registered just to help here…even if it is 3 years old. I hate when anyone creates a docker with hard coded uid and gid. The typical pattern I utilize to ā€œfixā€ this is to build a modified container w/ compose. It’s modestly annoying because you have to figure out what files in the container need to be chowned but once you know that, it’s easy enough.

docker-compose.yml

version: "3.9"
services:
  nexus:
    image: "custom-nexus3:latest"
    build:
      dockerfile: "nexus3.Dockerfile"
    container_name: nexus
    ports:
      - 8081:8081
    restart: always
    volumes:
      - "/opt/data/nexus/:/nexus-data"
volumes:
    nexus-vol:

nexus3.Dockerfile

FROM sonatype/nexus3:latest

USER root
ENV NEXUS_UID 1008
ENV NEXUS_GID 1008

RUN sed -i -re "s/^(nexus:[^:]):[0-9]*:/\1:$NEXUS_GID:/g" /etc/group
RUN sed -i -re "s/^(nexus:[^:]):[0-9]*:[0-9]*:/\1:$NEXUS_UID:$NEXUS_GID:/g" /etc/passwd

RUN chown -R nexus:nexus /opt/sonatype/sonatype-work

USER nexus

Then just ā€œdocker compose buildā€ and and ā€œdocker compose up -dā€

Thank you very much, good ole sed to the rescue! I saved this for later use. In the moment I have a block device with uid 200 mounted.

THOU SHALT NOT HARDCODE

Yea, I use sed because usermod and groupmod aren’t always available. Additionally, you could use find for the chown so you don’t need to know what files to chown ahead of time but then you have to figure out what the original id’s are first. This is untested but should do the thing.

FROM sonatype/nexus3:latest

USER root
ENV NEXUS_UID 1008
ENV NEXUS_GID 1008

RUN echo "export OLD_NEXUS_UID=`id -u nexus`" >> /envfile
RUN echo "export OLD_NEXUS_GID=`id -g nexus`" >> /envfile

RUN sed -i -re "s/^(nexus:[^:]):[0-9]*:/\1:$NEXUS_GID:/g" /etc/group
RUN sed -i -re "s/^(nexus:[^:]):[0-9]*:[0-9]*:/\1:$NEXUS_UID:$NEXUS_GID:/g" /etc/passwd

RUN . /envfile; find / -user $OLD_NEXUS_UID  -exec chown -h nexus {} \;
RUN . /envfile; find / -group $OLD_NEXUS_GID  -exec chgrp -h nexus {} \;

USER nexus
1 Like