The language-dockerfile package

[Tags:gpl, library, test]

Forked from hadolint.

All functions for parsing, printing and writting Dockerfiles are exported through Language.Dockerfile. For more fine-grained operations look for specific modules that implement a certain functionality.

There are two flags in this package, which enable building two executables:

See the GitHub project for the source-code and examples.

[Skip to Readme]


Dependencies base (>=4.8 && <5), bytestring (>=0.10), free, language-dockerfile, mtl, parsec (>=3.1), pretty, ShellCheck, split (>=0.2), template-haskell, th-lift, th-lift-instances, transformers [details]
License GPL-3
Copyright Lukas Martinelli, Copyright (c) 2016, Pedro Tacla Yamada, Copyright (c) 2016
Author Lukas Martinelli, Pedro Tacla Yamada
Stability Unknown
Category Development
Home page
Bug tracker
Source repository head: git clone
Uploaded Mon Oct 24 13:33:17 UTC 2016 by yamadapc
Distributions LTSHaskell:, NixOS:, Stackage:, Tumbleweed:
Downloads 237 total (8 in the last 30 days)
0 []
Status Docs available [build log]
Last success reported on 2016-10-29 [all 1 reports]




dockerfmtBuild the dockerfmt executableDisabledManual
hadolintBuild the hadolint executableDisabledManual

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info


Maintainer's Corner

For package maintainers and hackage trustees

Readme for language-dockerfile

Readme for language-dockerfile-


Build Status CircleCI


GH Pages Haddock

Blog Post in Portuguese

Dockerfile linter, parser, pretty-printer and embedded DSL, forked from hadolint.

Published on Hackage as language-dockerfile.

It extends hadolint with the pretty-printer and EDSL for writting Dockerfiles in Haskell.

Parsing files

import Language.Dockerfile
main = do
    ef <- parseFile "./Dockerfile"
    print ef

Parsing strings

import Language.Dockerfile
main = do
    c <- readFile "./Dockerfile"
    print (parseString c)

Pretty-printing files

import Language.Dockerfile
main = do
    Right d <- parseFile "./Dockerfile"
    putStr (prettyPrint d)

Writing Dockerfiles in Haskell

{-# LANGUAGE OverloadedStrings #-}
import Language.Dockerfile
main = putStr $ toDockerfileStr $ do
    from "node"
    run "apt-get update"
    runArgs ["apt-get", "install", "something"]
    -- ...

Using the QuasiQuoter

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes       #-}
import Language.Dockerfile
main = putStr $ toDockerfileStr $ do
    from "node"
    run "apt-get update"
    RUN apt-get update
    CMD node something.js
    -- ...

Templating Dockerfiles in Haskell

{-# LANGUAGE FlexibleContexts  #-}
{-# LANGUAGE OverloadedStrings #-}
import Control.Monad
import Language.Dockerfile
tags = ["7.8", "7.10", "8"]
cabalSandboxBuild packageName = do
    let cabalFile = packageName ++ ".cabal"
    run "cabal sandbox init"
    run "cabal update"
    add cabalFile ("/app/" ++ cabalFile)
    run "cabal install --only-dep -j"
    add "." "/app/"
    run "cabal build"
main =
    forM_ tags $ \tag -> do
        let df = toDockerfileStr $ do
            from ("haskell" `tagged` tag)
            cabalSandboxBuild "mypackage"
        writeFile ("./examples/templating-" ++ tag ++ ".dockerfile") df

Using IO in the DSL

By default the DSL runs in the Identity monad. By running in IO we can support more features like file globbing:

{-# LANGUAGE OverloadedStrings #-}
import           Language.Dockerfile
import qualified System.Directory     as Directory
import qualified System.FilePath      as FilePath
import qualified System.FilePath.Glob as Glob
main = do
    str <- toDockerfileStrIO $ do
        fs <- liftIO $ do
            cwd <- Directory.getCurrentDirectory
            fs <- Glob.glob "./test/*.hs"
            return (map (FilePath.makeRelative cwd) fs)
        from "ubuntu"
        mapM_ (\f -> add f ("/app/" ++ FilePath.takeFileName f)) fs
    putStr str