Created
February 4, 2019 02:25
-
-
Save zultron/2c199229e53b6852d0523c69bb413c25 to your computer and use it in GitHub Desktop.
Docker entrypoint script to edit `/etc/hosts` and `/etc/passwd` at container init time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
# add hostname to hosts | |
sh -c 'echo "127.0.2.1 `hostname`" >> /etc/hosts' | |
# Start rsyslog for MK logging | |
service rsyslog start | |
# Add user and group to system | |
echo "${USER}:x:${UID}:${GID}::${HOME}:/bin/bash" >>/etc/passwd | |
echo "${USER}:x:${GID}:" >>/etc/group | |
sed -i '/.*dialout.*:/ s/$/'${USER}'/' /etc/group | |
sed -i '/.*plugdev.*:/ s/$/'${USER}'/' /etc/group | |
# Create RT cgroup | |
if test -n "${RT_CPUS}"; then | |
export RT_CGNAME=/rt | |
cgcreate -g cpuset:${RT_CGNAME} | |
cgset -r cpuset.mems=0 ${RT_CGNAME} | |
cgset -r cpuset.cpus=${RT_CPUS} ${RT_CGNAME} | |
cgset -r cpuset.cpu_exclusive=1 ${RT_CGNAME} | |
cgset -r cpuset.sched_load_balance=0 ${RT_CGNAME} | |
fi | |
# Run command as user | |
default_cmd=(/bin/bash --login -i) | |
exec sudo -u ${USER} -E "${@:-${default_cmd[@]}}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In the
Dockerfile
, add:Then run the container with appropriate variables set: