Skip to content

Use a Data Volume Container rather than a local fs mount #8

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
USER=tronpaul

build:
docker build -t ${USER}/znc .

Expand Down
28 changes: 16 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/

Expand All @@ -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
Expand All @@ -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.

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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`
44 changes: 43 additions & 1 deletion docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# Options.
DATADIR="/znc-data"
DEFAULT_NICK="admin"

# Build modules from source.
if [ -d "${DATADIR}/modules" ]; then
Expand All @@ -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 <<EOF > ${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
<Listener l>
Port = 6667
IPv4 = true
IPv6 = true
SSL = false
</Listener>
LoadModule = webadmin

<User ${ZNC_USER:-admin}>
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
</User>
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
Expand Down
34 changes: 0 additions & 34 deletions znc.conf.default

This file was deleted.