diff --git a/Dockerfile b/Dockerfile index d6fcadc..b2dff03 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,6 @@ # docker-version 1.8.2 FROM ubuntu:15.04 MAINTAINER Jim Myhrberg "contact@jimeh.me" - ENV ZNC_VERSION 1.6.1 RUN apt-get update \ diff --git a/Makefile b/Makefile index fc3acdb..76f995d 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +USER=tronpaul + build: docker build -t ${USER}/znc . diff --git a/README.md b/README.md index ce30cf3..a918962 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,8 @@ Run the [ZNC][] IRC Bouncer in a Docker container. ## Prerequisites -1. Install [Docker][]. -2. Make .znc folder: `mkdir $HOME/.znc` +1. Install [Docker][] +2. Make .znc container: `docker run -v /znc-data --name znc-data busybox echo Data-only container for znc` [Docker]: http://docker.io/ @@ -17,7 +17,7 @@ To retain your ZNC settings between runs, you'll most likely want to bind a directory from the host to `/znc-data` in the container. For example: - docker run -d -p 6667 -v $HOME/.znc:/znc-data jimeh/znc + docker run -d -p 6667 --volumes-from znc-data jimeh/znc This will download the image if needed, and create a default config file in your data directory unless you already have a config in place. The default @@ -28,7 +28,7 @@ exposed: Or if you want to specify which port to map the default 6667 port to: - docker run -d -p 36667:6667 -v $HOME/.znc:/znc-data jimeh/znc + docker run -d -p 36667:6667 --volumes-from znc-data jimeh/znc Resulting in port 36667 on the host mapping to 6667 within the container. @@ -60,13 +60,16 @@ down ZNC's startup with a few seconds. ZNC needs a data/config directory to run. Within the container it uses `/znc-data`, so to retain this data when shutting down a container, you should -mount a directory from the host. Hence `-v $HOME/.znc:/znc-data` is part of -the instructions above. +use the volume from another persistent container. Hence `--volumes-from znc-data` +is part of the instructions above. -As ZNC needs to run as it's own user within the container, the directory will -have it's ownership changed to UID 1000 (user) and GID 1000 (group). Meaning -after the first run, you might need root access to manually modify the data -directory. +You'll want to periodically back up your znc data to the host fs: + + docker run --volumes-from znc-data -v $(pwd):/backup ubuntu tar cvf /backup/backup.tar /znc-data + +And restore them later: + + docker run --volumes-from znc-data -v $(pwd):/backup busybox tar xvf /backup/backup.tar ## Passing Custom Arguments to ZNC @@ -78,7 +81,7 @@ script, the [start-znc][] script simply passes all arguments along to ZNC. For example, if you want to use the `--makepass` option, you would run: - docker run -i -t -v $HOME/.znc:/znc-data jimeh/znc --makepass + docker run -i -t --volumes-from znc-data jimeh/znc --makepass Make note of the use of `-i` and `-t` instead of `-d`. This attaches us to the container, so we can interact with ZNC's makepass process. With `-d` it would @@ -90,4 +93,5 @@ simply run in the background. 1. Follow Prerequisites above. 2. Checkout source: `git clone https://github.com/jimeh/docker-znc.git && cd docker-znc` 3. Build container: `sudo docker build -t $(whoami)/znc .` -4. Run container: `sudo docker run -d -p 6667 -v $HOME/.znc:/znc-data $(whoami)/znc` +4. Make data container: `sudo docker run -v /znc-data --name znc-data jimeh/znc echo Data-only container for znc` +5. Run container: `sudo docker run -d -p 6667 --volumes-from znc-data $(whoami)/znc` diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index d2a8701..5cb82bb 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -2,6 +2,7 @@ # Options. DATADIR="/znc-data" +DEFAULT_NICK="admin" # Build modules from source. if [ -d "${DATADIR}/modules" ]; then @@ -24,7 +25,48 @@ fi # Create default config if it doesn't exist if [ ! -f "${DATADIR}/configs/znc.conf" ]; then mkdir -p "${DATADIR}/configs" - cp /znc.conf.default "${DATADIR}/configs/znc.conf" + cat < ${DATADIR}/configs/znc.conf +// WARNING +// +// Do NOT edit this file while ZNC is running! +// Use webadmin or *controlpanel instead. +// +// Altering this file by hand will forfeit all support. +// +// But if you feel risky, you might want to read help on /znc saveconfig and /znc rehash. +// Also check http://en.znc.in/wiki/Configuration + +Version = 1.6.1 + + Port = 6667 + IPv4 = true + IPv6 = true + SSL = false + +LoadModule = webadmin + + + Pass = ${ZNC_PASSWORD:-sha256#00793765305dfc3e7bba28267fe9d9e2c721ebef4e20f3a89720265a89ee6a4f#N!lgZM8S.HZ4zH?)vFoW#} + Admin = true + Nick = ${ZNC_NICK:=$DEFAULT_NICK} + AltNick = ${ZNC_NICK:=$DEFAULT_NICK}_ + Ident = ${ZNC_NICK:=$DEFAULT_NICK} + RealName = Got ZNC? + Buffer = 50 + AutoClearChanBuffer = true + ChanModes = +stn + + LoadModule = chansaver + LoadModule = controlpanel + LoadModule = perform + +EOF + +fi + +# Create a pemfile if it doesn't exist +if [ ! -f "${DATADIR}/znc.pem" ]; then + znc --datadir="$DATADIR" --makepem fi # Make sure $DATADIR is owned by znc user. This effects ownership of the diff --git a/znc.conf.default b/znc.conf.default deleted file mode 100644 index bab6c0d..0000000 --- a/znc.conf.default +++ /dev/null @@ -1,34 +0,0 @@ -// WARNING -// -// Do NOT edit this file while ZNC is running! -// Use webadmin or *controlpanel instead. -// -// Altering this file by hand will forfeit all support. -// -// But if you feel risky, you might want to read help on /znc saveconfig and /znc rehash. -// Also check http://en.znc.in/wiki/Configuration - -Version = 1.6.1 - - Port = 6667 - IPv4 = true - IPv6 = true - SSL = false - -LoadModule = webadmin - - - Pass = sha256#00793765305dfc3e7bba28267fe9d9e2c721ebef4e20f3a89720265a89ee6a4f#N!lgZM8S.HZ4zH?)vFoW# - Admin = true - Nick = admin - AltNick = admin_ - Ident = admin - RealName = Got ZNC? - Buffer = 50 - AutoClearChanBuffer = true - ChanModes = +stn - - LoadModule = chansaver - LoadModule = controlpanel - LoadModule = perform -