A primitive docker container management script for regenerating container from fresh images
Useful for setups not using docker-compose or more high level container orchestration
It's a bash script that reads a convenient properties file that describes your container. It then pulls the latest image and rebuilds your container using your supplied options.
I kept on writing slightly different versions of the same script
Better to just have one script and an simple properties file. (Better for me anyway)
Oh By the way, it's pronounced "yeown" and means "OK" in Welsh. I'd rather not explain the full name in this context, suffice to say if you live in Caernarfon it is considered a warm greeting, elsewhere... not so much :)
Here's the bundled example which runs a shell loop.
# File: bbtest.conf
# the latest image tag you want to run
VERSION=latest
#
# the image in full repository/image syntax if needed
IMAGE=busybox
#
# the runtime name of your container (shouldn't change)
CONT_NAME=bbtest
#
# bash array syntax for options for docker create
CONT_OPTS=(-v "/tmp/rob:/tmp/rob")
#
# bash array syntax for extra docker CMD args
CONT_ARGS=(sh -c "while true; do echo 'running'; sleep 10; done")
#
# link the docker host's IP address as host "docker.local" in the container
LINK_LOCAL=false
Calling the script with the path to the properties file will pull the image, but will only build the container if it isn't running If you want to do a lengthy pull before shutting down the container just run it first anyway.
-
edit /path/to/properties.conf and bump VERSION
-
/path/to/recreateContainer /path/to/properties.conf
# to pull -
Stop your container so it can be rebuilt (E.g. docker stop <container>)
-
/path/to/recreateContainer /path/to/properties.conf
# to re-create -
Start your new container. (E.g. docker start <container>)
To back-to-back the whole show, chain the routine as per the bundled example:
/recreateContainer bbtest.conf; docker stop bbtest; ./recreateContainer bbtest.conf; docker start bbtest
For my convenience I have bundled the systemd template from https://docs.docker.com/engine/admin/host_integration/ Ignore this for other process management regimes.
cp docker-container@.service /etc/systemd/system/
systemctl enable docker-container\@.service
./recreateContainer bbtest.conf
systemctl enable docker-container\@bbtest.service
- edit bbtest.conf and bump version
./recreateContainer bbtest.conf
# to pullsystemctl stop docker-container@bbtest.service
./recreateContainer bbtest.conf
# to recreatesystemctl start docker-container@bbtest.service
if using the systemd container template, it uses docker -a to allow signal forwarding and to stay in the foreground. This means that in addition to there being the usual docker logs from your configured logging driver (e.g. json-file) you will also see docker container stdout & stderr passing through the hosts system logger. I.e. on ubuntu rsyslog will dump all the containers' output to /var/log/syslog.
To supress this add the following file and restart rsyslog
# begin /etc/rsyslog.d/30-nodockersyslog.conf
if $programname == 'docker' then ~
& stop
# end /etc/rsyslog.d/30-nodockersyslog.conf