Taskwarrior in a Docker container

So I heard about great tool - Taskwarrior. Cool, let's try it. Well, sure, but why should I install another bunch of RPMs to my laptop? Not that it matters a lot, but I hate to have my system bloated with unused packages which are installed as dependencies, but stay there when I remove the "root" package. Let's go crazy and create a simple Taskwarrior container.

I started with plain Dockerfile.

FROM fedora
MAINTAINER Vaclav Pavlin <vpavlin@redhat.com>
RUN dnf -y install task
VOLUME /task_data


That was not ideal because the final container missed very important settings - data location. So I added 2 lines which initialized ~/.taskrc and changed the data location to a well known path. I also added man command to the mix so that I can display manual pages for Taskwarrior. Final Dockerfile follows

FROM fedora
MAINTAINER Vaclav Pavlin <vpavlin@redhat.com>
RUN dnf -y install task man
VOLUME /task_data
RUN yes | task || true
RUN sed -i 's#\(data.location=\).*#\1/task_data#' ~/.taskrc

Still pretty simple, isn't it? Now, how to run this image? Just call the following command, there is an image ready for you on Docker Hub:

docker run -it --rm -v $HOME/.task:/task_data vpavlin/task

The command above will start a container which will initialize few files in $HOME/.task directory and print output like this:

[task next]
No matches.

You can try some fancy stuff with Taskwarrior itself now:

Screenshot from 2015-08-18 16-40-32Well, it works. But also is pretty ugly. Let's make the user experience nicer and smoother. You can simply create an alias for docker run command. For example like this one:

$ alias task="docker run -it --rm -v $HOME/.task:/task_data vpavlin/task"
$ task
[task next]

ID Age Project Tag Description Urg 
 1 6s vpavlin.eu blog today This is a test taks for my blog post 1.9

1 task

Then, when you call task, you will get the same output as if Taskwarrior was installed on you machine. Also your data will be stored locally so you don't have to be afraid of losing them when you remove container/image.

I also wrote a simple task function which you can paste in your ~/.bash_aliases file which lets you either use Taskwarrior as with the alias above, or you can do

task CMD man task

Note CMD in the command - that will let the bash function know to run different command than the one specified in Dockerfile - f.e. view the man pages.

I also strongly suggest to set the data location (i.e. the volume mount, or $data_dir variable in the function) to a backed up folder. I, for example, use Dropbox, so that I can access and modify my tasks from any machine (basically just by pulling and running the Docker image).



Leave a Reply

Your email address will not be published. Required fields are marked *