Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
embltilities
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Renato Alves
embltilities
Commits
eb01b0f1
Verified
Commit
eb01b0f1
authored
7 years ago
by
Renato Alves
Browse files
Options
Downloads
Patches
Plain Diff
ENH Add docker_wrap script mentioned in last Bio-IT session
parent
8a5af2a2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.rst
+2
-0
2 additions, 0 deletions
README.rst
bin/docker_wrap.sh
+73
-0
73 additions, 0 deletions
bin/docker_wrap.sh
with
75 additions
and
0 deletions
README.rst
+
2
−
0
View file @
eb01b0f1
...
...
@@ -6,3 +6,5 @@ EMBL utilities
``submitjob`` - a polyglot script that submits jobs to SGE, LSF and SLURM clusters.
``q`` - shortcut to query state of own jobs across queue systems (SLURM, LSF and SGE)
``docker_wrap.sh`` - a convenience script to start a container that shares the user's home and creates a user to ensure consistent permissions.
This diff is collapsed.
Click to expand it.
bin/docker_wrap.sh
0 → 100755
+
73
−
0
View file @
eb01b0f1
#!/usr/bin/env sh
# docker_wrap.sh -- created 2017-02-09 - Renato Alves
usage
()
{
echo
>
&2
"This command launches a docker container automatically mounting"
echo
>
&2
"the user's home folder on /remote and creating a user to ensure"
echo
>
&2
"compatible execution permissions"
echo
>
&2
""
echo
>
&2
"Usage:"
echo
>
&2
"
$0
[options] docker_image"
echo
>
&2
""
exit
1
}
setup_user
()
{
NEWUSER
=
"dockeruser"
NEWGROUP
=
"
$NEWUSER
"
NEWUID
=
"
$(
stat
-c
'%u'
"
$TARGET
"
)
"
NEWGID
=
"
$(
stat
-c
'%g'
"
$TARGET
"
)
"
echo
">>> checking for group
$NEWGID
"
if
!
getent group
"
$NEWGID
"
>
/dev/null 2>/dev/null
;
then
busybox addgroup
-g
"
$NEWGID
"
"
$NEWUSER
"
||
(
echo
"!!! Couldn't create group with id
$NEWGID
"
&&
exit
1
)
echo
">>> created group
$NEWGROUP
(
$NEWGID
)"
else
NEWGROUP
=
"
$(
getent group
"
$NEWGID
"
|
cut
-d
:
-f1
)
"
echo
"~~~ group
$NEWGROUP
(
$NEWGID
) already exists"
fi
echo
">>> checking for user
$NEWUID
"
if
!
getent passwd
"
$NEWUID
"
>
/dev/null 2>/dev/null
;
then
busybox adduser
-G
"
$NEWGROUP
"
-u
"
$NEWUID
"
-h
"
$TARGET
"
-s
/bin/sh
-D
"
$NEWUSER
"
||
(
echo
"!!! Couldn't create user"
&&
exit
1
)
echo
">>> created user
$NEWUSER
(
$NEWUID
)"
else
NEWUSER
=
"
$(
getent passwd
"
$NEWUID
"
|
cut
-d
:
-f1
)
"
echo
"~~~ user
$NEWUSER
(
$NEWUID
) already exists"
fi
echo
"root:r"
| busybox chpasswd
echo
">>> password set on the root user"
echo
">>> use 'su -' and password 'r' to become super-user"
chmod
u+s /bin/su
exec
/bin/su -
"
$NEWUSER
"
}
[
"x
$1
"
=
"x"
]
&&
usage
# Get the name of the image filtering for allowed characters and use it as hostname later
IMAGE
=
"
$(
for
last
in
"
$@
"
;
do
:
;
done
;
echo
"
$last
"
|
tr
':'
'-'
|
tr
-cd
'A-Za-z0-9_-'
)
"
TARGET
=
"/remote"
WRAPPER_OPTION
=
"--setup-docker-wrapper"
if
[
"
$1
"
=
"
$WRAPPER_OPTION
"
]
;
then
setup_user
else
USERHOME
=
"
$(
readlink
-f
~
)
"
WRAPPER_LOCAL
=
"
$(
readlink
-f
"
$0
"
)
"
WRAPPER
=
"
${
TARGET
}${
WRAPPER_LOCAL
#
$USERHOME
}
"
# Ensure we managed to get a valid location for the wrapper script
if
[
"
$WRAPPER
"
!=
"
${
TARGET
}
/
$(
basename
"
$0
"
)
"
]
;
then
if
[
"
$WRAPPER
"
=
"
${
TARGET
}${
WRAPPER_LOCAL
}
"
]
;
then
echo
"ERROR: Unexpected location for
$0
inside the container."
echo
" Obtained:
$WRAPPER
"
echo
"For this to work
$0
needs to be inside the user's home folder"
exit
1
fi
fi
if
[
-d
/data
]
;
then
DATAVOLUME
=
"-v /data:/data:rw"
else
DATAVOLUME
=
fi
docker run
-it
-h
"
$IMAGE
"
$DATAVOLUME
-v
"
$USERHOME
"
:
"
$TARGET
"
:rw
"
$@
"
"
$WRAPPER
"
"
$WRAPPER_OPTION
"
fi
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment