Skip to content

Instantly share code, notes, and snippets.

@lucabrunox
Created April 14, 2016 18:46
Show Gist options
  • Save lucabrunox/7e39f8f38c6190dbf26b071e3bfd6188 to your computer and use it in GitHub Desktop.
Save lucabrunox/7e39f8f38c6190dbf26b071e3bfd6188 to your computer and use it in GitHub Desktop.
{ pkgs ? import <nixpkgs> {} }:
with pkgs;
let
entrypoint = writeScript "entrypoint.sh" ''
#!${stdenv.shell}
set -e
# allow the container to be started with `--user`
if [ "$1" = "redis-server" -a "$(${coreutils}/bin/id -u)" = "0" ]; then
chown -R redis .
exec ${goPackages.gosu.bin}/bin/gosu redis "$BASH_SOURCE" "$@"
fi
exec "$@"
'';
in
dockerTools.buildImage {
name = "redis";
runAsRoot = ''
#!${stdenv.shell}
${dockerTools.shadowSetup}
groupadd -r redis
useradd -r -g redis -d /data -M redis
mkdir /data
chown redis:redis /data
'';
contents = [ redis ];
config = {
Cmd = [ "redis-server" ];
Entrypoint = [ entrypoint ];
ExposedPorts = {
"6379/tcp" = {};
};
WorkingDir = "/data";
Volumes = {
"/data" = {};
};
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment