There are times when I need to supply config to the container at runtime. I may need to set my proxy settings, or I might need to toggle some application flags, etc. I needed a base image that would bootstrap itself when passed known flags or options. This is easy enough to do with the Docker ENTRYPOINT
, but I also wanted to freely switch between users in my container.
This repository documents my efforts. I hope you find it useful to you.
You will need to install git
if you haven't already. Then execute the following commands on from your terminal. It should work on OS X, Linux, and MinGW.
git clone https://www.github.com/neveroddoreven/alpine-bash-profile.git alpine-bash-profile
cd alpine-bash-profile
docker build -t "neveroddoreven/alpine-bash-profile:latest" .
I like to run containerized apps with user-level privileges. Is it overkill? No idea. I see no reason to dismiss good security practices just because it is a container.
This image is configured with two users: root
and appuser
. Both belong to the appusers
group. Neither user requires a password, and either one may be used when starting a container.
If you have not built the image, then you may also use the docker
client to pull the build from docker hub. You will need to install Docker CE
if you have not already done so.
docker pull neveroddoreven/alpine-bash-profile:latest
~ $ docker run -it --rm "neveroddoreven/alpine-bash-profile:latest"
~ $ docker run -it --rm -u appuser "neveroddoreven/alpine-bash-profile:latest"
Welcome appuser, from '/etc/bashrc'
Sourced by: /bin/bash.
This is not an interactive shell
This is not a login shell
Welcome appuser, from '/usr/share/entrypoint.sh'
This is not an interactive shell
This is not a login shell
appuser ~ $
~ $ docker run -it --rm -u root "neveroddoreven/alpine-bash-profile:latest"
Welcome appuser, from '/etc/bashrc'
Sourced by: /bin/bash.
This is not an interactive shell
This is not a login shell
Welcome appuser, from '/usr/share/entrypoint.sh'
This is not an interactive shell
This is not a login shell
appuser ~ #
~ $ docker run -it --rm "neveroddoreven/alpine-bash-profile:latest" --some-var "some var"
Welcome appuser, from '/etc/bashrc'
Sourced by: /bin/bash.
This is not an interactive shell
This is not a login shell
Welcome appuser, from '/usr/share/entrypoint.sh'
This is not an interactive shell
This is not a login shell
Setting known flags
export SOME_VAR='some var'
appuser ~ $ echo $SOME_VAR
some var
~ $ docker run -it --rm "neveroddoreven/alpine-bash-profile:latest" -? "some var"
Welcome appuser, from '/etc/bashrc'
Sourced by: /bin/bash.
This is not an interactive shell
This is not a login shell
Welcome appuser, from '/usr/share/entrypoint.sh'
This is not an interactive shell
This is not a login shell
These unknown options were not processed
-?
some var
appuser ~ $ sudo su - root
Welcome root, from '/etc/profile.d/welcome.sh'
Sourced by: -bash.
This is an interactive shell
This is a login shell
root ~ $ su - appuser
Welcome appuser, from '/etc/profile.d/welcome.sh'
Sourced by: -bash.
This is an interactive shell
This is a login shell
This is published under the MIT open source license.