Skip to content

Commit edf2b0f

Browse files
authored
Add Dockerfile enhancements and usage documentation (#810)
Enhance the Dockerfile by sourcing aliases in the user's .bashrc for non-interactive logins and refactor entrywrapper.sh for improved UID/GID remapping and ownership handling. Include detailed Docker usage instructions in the running documentation.
2 parents 5c297dd + e9650fb commit edf2b0f

5 files changed

Lines changed: 117 additions & 3 deletions

File tree

Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,9 @@ COPY --chown=mambauser:mambauser dockerfiles/docker_tests /home/mambauser/Code/A
9191
COPY --chmod=755 dockerfiles/entrywrapper.sh /usr/local/bin/entrywrapper.sh
9292
COPY --chmod=644 dockerfiles/aliases.sh /etc/profile.d/aliases.sh
9393
COPY --chmod=755 dockerfiles/aliases_print.sh /usr/local/bin/aliases
94+
RUN touch /home/mambauser/.bashrc && \
95+
grep -qxF 'source /etc/profile.d/aliases.sh' /home/mambauser/.bashrc || \
96+
echo 'source /etc/profile.d/aliases.sh' >> /home/mambauser/.bashrc
9497

98+
USER root
9599
ENTRYPOINT ["/usr/local/bin/entrywrapper.sh"]

dockerfiles/entrywrapper.sh

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,44 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4-
# 0) Only try chown if we're root (bind-mounts may be root-owned)
5-
if [[ "$(id -u)" -eq 0 ]] && [[ ! -O /home/mambauser/Code ]]; then
6-
chown -R mambauser:mambauser /home/mambauser/Code || true
4+
# 0) If root, optionally remap mambauser UID/GID for bind mounts, then drop privileges.
5+
if [[ "$(id -u)" -eq 0 ]]; then
6+
if [[ -n "${PGID:-}" ]]; then
7+
existing_group=""
8+
if getent group "$PGID" >/dev/null; then
9+
existing_group="$(getent group "$PGID" | cut -d: -f1)"
10+
fi
11+
if [[ -n "$existing_group" && "$existing_group" != "mambauser" ]]; then
12+
echo "Error: requested PGID '$PGID' is already in use by group '$existing_group', cannot remap mambauser group." >&2
13+
exit 1
14+
fi
15+
groupmod -g "$PGID" mambauser
16+
fi
17+
if [[ -n "${PUID:-}" ]]; then
18+
current_uid="$(id -u mambauser)"
19+
if [[ "$PUID" != "$current_uid" ]]; then
20+
if getent passwd "$PUID" >/dev/null; then
21+
echo "Error: Cannot remap mambauser to UID '$PUID' because it is already in use by another user." >&2
22+
exit 1
23+
fi
24+
usermod -u "$PUID" mambauser
25+
fi
26+
fi
27+
28+
if [[ -d /home/mambauser/Code ]]; then
29+
if ! chown -R mambauser:mambauser /home/mambauser/Code; then
30+
echo "warning: failed to change ownership of /home/mambauser/Code to mambauser:mambauser (read-only mount or permission issue?)" >&2
31+
fi
32+
fi
33+
if [[ -d /work ]]; then
34+
if ! chown -R mambauser:mambauser /work; then
35+
echo "warning: failed to change ownership of /work to mambauser:mambauser (read-only mount or permission issue?)" >&2
36+
fi
37+
fi
38+
39+
if [[ "${ENTRYWRAPPER_AS_USER:-0}" != "1" ]]; then
40+
exec runuser -u mambauser -- env ENTRYWRAPPER_AS_USER=1 /usr/local/bin/entrywrapper.sh "$@"
41+
fi
742
fi
843

944
# If running non-interactively at container root and /work exists; it will go there

docs/source/docker.rst

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
.. _docker:
2+
3+
Docker image
4+
============
5+
6+
The published Docker image includes ARC and RMG along with convenience entrypoints.
7+
Bind-mount your working directory and pass an input file path that exists inside
8+
the container. For best write access on bind mounts, pass your host UID/GID as
9+
``PUID``/``PGID`` (the entrypoint remaps the ``mambauser`` account).
10+
11+
Run ARC non-interactively::
12+
13+
docker run --rm \
14+
-v "$PWD:/work" -w /work \
15+
-e PUID=$(id -u) -e PGID=$(id -g) \
16+
laxzal/arc:latest arc my_case/input.yml
17+
18+
Run RMG non-interactively::
19+
20+
docker run --rm \
21+
-v "$PWD:/work" -w /work \
22+
-e PUID=$(id -u) -e PGID=$(id -g) \
23+
laxzal/arc:latest rmg my_case/input.py
24+
25+
Manual RMG invocation::
26+
27+
docker run --rm \
28+
-v "$PWD:/work" -w /work \
29+
-e PUID=$(id -u) -e PGID=$(id -g) \
30+
laxzal/arc:latest \
31+
micromamba run -n rmg_env python /home/mambauser/Code/RMG-Py/rmg.py my_case/input.py
32+
33+
Manual ARC invocation::
34+
35+
docker run --rm \
36+
-v "$PWD:/work" -w /work \
37+
-e PUID=$(id -u) -e PGID=$(id -g) \
38+
laxzal/arc:latest \
39+
micromamba run -n arc_env python /home/mambauser/Code/ARC/ARC.py my_case/input.yml
40+
41+
Open an interactive shell::
42+
43+
docker run --rm -it \
44+
-v "$PWD:/work" -w /work \
45+
-e PUID=$(id -u) -e PGID=$(id -g) \
46+
laxzal/arc:latest
47+
48+
For job submission, the scheduler client tools must be available in the container
49+
or accessed via SSH on a remote host.
50+
51+
Aliases in interactive shells
52+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
53+
54+
When you open an interactive shell, the image provides these aliases::
55+
56+
rc # reload ~/.bashrc
57+
rce, erc # edit ~/.bashrc with nano
58+
59+
mamba, conda # micromamba
60+
deact # micromamba deactivate
61+
62+
rmge, arce # activate rmg_env / arc_env
63+
64+
rmgcode # cd to /home/mambauser/Code/RMG-Py
65+
dbcode # cd to /home/mambauser/Code/RMG-database
66+
arcode # cd to /home/mambauser/Code/ARC
67+
68+
rmg # run RMG with input.py, tee logs
69+
arkane # run Arkane with input.py, tee logs
70+
arc # run ARC with input.yml, tee logs
71+
arcrestart # run ARC with restart.yml, tee logs

docs/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Documentation Contents
3535
:maxdepth: 2
3636

3737
installation
38+
docker
3839
running
3940
examples
4041
advanced

docs/source/installation.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ Note:
1111
ARC was only tested on Linux (Ubuntu_ 18.04.1 and 20.04 LTS) and Mac machines.
1212
We don't expect it to work smoothly on Windows machines.
1313

14+
Note:
15+
For a containerized setup, see the :ref:`Docker image <docker>` documentation.
16+
1417
Note:
1518
These installation instructions assume you already have access to a server with a cluster scheduling software
1619
(ARC currently supports SGE, Slurm, PBS, and HTCondor) and with properly installed electronic structure software

0 commit comments

Comments
 (0)