Skip to content

A simple Docker image setup to load the system bashrc file when run, and the system profile when changing users within the container.

License

Notifications You must be signed in to change notification settings

NeverOddOrEven/alpine-bash-profile

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

An Alpine Image with Bash Runtime Configuration

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.

Building

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" .

Users and Permissions

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.

Running the 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

Running as appuser (the default user)

~ $ docker run -it --rm "neveroddoreven/alpine-bash-profile:latest"
~ $ docker run -it --rm -u appuser "neveroddoreven/alpine-bash-profile:latest"
Output
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 ~ $

Running as root

~ $ docker run -it --rm -u root "neveroddoreven/alpine-bash-profile:latest"
Output
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 ~ #

Running While Passing a Known Flag

~ $ docker run -it --rm "neveroddoreven/alpine-bash-profile:latest" --some-var "some var"
Output
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

Running While Passing an Unknown Option

~ $ docker run -it --rm "neveroddoreven/alpine-bash-profile:latest" -? "some var"
Output
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

Switching User - appuser to root

appuser ~ $ sudo su - root
Output
Welcome root, from '/etc/profile.d/welcome.sh'
Sourced by: -bash.

This is an interactive shell
This is a login shell

Switching User - root to appuser

root ~ $ su - appuser
Output
Welcome appuser, from '/etc/profile.d/welcome.sh'
Sourced by: -bash.

This is an interactive shell
This is a login shell

License

This is published under the MIT open source license.

About

A simple Docker image setup to load the system bashrc file when run, and the system profile when changing users within the container.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published