High level Haskell bindings to LXC (Linux containers). https://github.com/fizruk/lxc

Latest on Hackage:0.3.2

This package is not currently in any snapshots. If you're interested in using it, we recommend adding it to Stackage Nightly. Doing so will make builds more reliable, and allow stackage.org to host generated Haddocks.

BSD3 licensed by Nickolay Kudasov


Hackage package Build Status

High level Haskell bindings to LXC (Linux containers).

The library provides Haskell LXC API, wrapping bindings-lxc package.


Before installation make sure you have LXC installed on your system with header files and static library.

Although there is lxc-dev package in standard Ubuntu repositories, you might want to use ppa:ubuntu-lxc/stable repository instead:

$ sudo apt-get install software-properties-common python-software-properties
$ sudo add-apt-repository ppa:ubuntu-lxc/stable
$ sudo apt-get update
$ sudo apt-get install lxc-dev


Get the latest stable version from Hackage:

$ cabal install lxc

or clone this repository:

$ git clone https://github.com/fizruk/lxc.git
$ cd lxc
$ cabal install


Haddock documentation is available at http://fizruk.github.io/lxc/docs/


Most of container-related functions (e.g. start, attach, destroy) perform in a LXC monad. To run LXC a computation you need to specify a container using withContainer function. When working with a single container it might be handy to have an alias like this:

let containerName = withContainer (Container "container-name" configPath)

You can start using Haskell LXC API bindings similar to a command line tool from GHCi:

$ ghci
>>> import System.LXC
>>> let trusty = withContainer (Container "trusty" Nothing)
>>> trusty $ create "download" Nothing Nothing [] ["-d", "ubuntu", "-r", "trusty", "-a", "amd64"]
Using image from local cache
Unpacking the rootfs

You just created an Ubuntu container (release=trusty, arch=amd64, variant=default)
The default username/password is: ubuntu / ubuntu
To gain root privileges, please use sudo.

>>> trusty $ start False []
>>> trusty state
>>> trusty $ attachRunWait defaultAttachOptions "echo" ["echo", "Hello, world!"]
Hello, world!
Just ExitSuccess
>>> trusty stop
>>> Just trustySnapC <- trusty $ clone (Just "trusty-snap") Nothing [CloneSnapshot] Nothing Nothing Nothing []
>>> let trustySnap = withContainer trustySnapC
>>> trustySnap $ start False []
>>> trustySnap getInterfaces
>>> trustySnap $ getIPs "eth0" "inet" 0
>>> trustySnap $ shutdown (-1)
>>> trustySnap state

For more examples, please see examples/ folder.


Contributions and bug reports are welcome!

Please feel free to contact me via GitHub or on the #haskell IRC channel on irc.freenode.net.

-Nickolay Kudasov



  • Relax upper bound for base
  • Fix warnings

  • Loose mtl and transformers dependencies for lxc to play nice with other libraries


  • Add snapshotDestroy to System.LXC.Container
  • Improve documentation slightly


  • Introduce LXC monad
  • Add transformers and mtl dependencies
  • Change container-related functions to use LXC monad
  • Change listContainers functions to return [Container] instead of [(String, Ptr C'lxc_container)]
  • Remove mkContainer function
  • Remove getRef and dropRef from System.LXC.Container
  • Make Container a pure Haskell data structure
  • Add examples/
  • Add C'lxc_container marshalling helpers (e.g. withC'lxc_container) to Internal
  • Fix potential segfaults in snapshotList and list*Containers


  • Handle LXC errors through getLastError function
  • Add getDaemonize function
  • Fix start function (and changed type)
  • Add Show instance for BDevSpecs
  • Update documentation (haddock and README)


  • Fix bindings-lxc dependency
  • Expose System.LXC.Internal.AttachOptions module
Depends on 4 packages:
Used by 1 package:
comments powered byDisqus