#+TITLE: Docker layer

#+TAGS: layer|tool

[[file:img/docker.png]]

* Table of Contents                     :TOC_5_gh:noexport:
- [[#description][Description]]
  - [[#features][Features:]]
- [[#install][Install]]
  - [[#docker][Docker]]
  - [[#linting][Linting]]
  - [[#lsp][LSP]]
- [[#usage][Usage]]
  - [[#tramp-access-to-docker-containers][TRAMP access to docker containers]]
- [[#key-bindings][Key bindings]]

* Description
This layer integrates basic container management into Spacemacs.

** Features:
- Syntax highlighting for =Docker= files
- =Docker= build integration
- =TRAMP= access to running Docker containers
- =Docker= container and image management via [[https://github.com/Silex/docker.el][docker.el]]
- =docker-compose= integration via [[https://github.com/Silex/docker.el][docker.el]]
- Syntax checking via [[https://github.com/hadolint/hadolint][hadolint]]
- Code-Completion via =lsp=

* Install
** Docker
To use this configuration layer, add it to your =~/.spacemacs=. You will need to
add =docker= to the existing =dotspacemacs-configuration-layers= list in this
file.

You will also need the native package [[https://www.docker.com/][Docker]] for the actual container management.

** Linting
For syntax checking the external library [[https://github.com/hadolint/hadolint][hadolint]] is necessary.
It can either be downloaded from [[https://github.com/hadolint/hadolint/releases/latest][=here=]] or
build locally with stack as shown below:

#+BEGIN_SRC sh
  stack install hadolint
#+END_SRC

** LSP
This layer can be enhanced with [[https://github.com/rcjsuen/dockerfile-language-server-nodejs][=dockerfile-language-server-nodejs=]] and emacs
[[https://github.com/emacs-lsp/lsp-mode][=lsp-mode=]] to provide richer, IDE-like capabilities.
To do so set the layer variable =docker-dockerfile-backend= to =lsp= like shown below:

#+BEGIN_SRC emacs-lisp
  (setq-default dotspacemacs-configuration-layers
                '((docker :variables docker-dockerfile-backend 'lsp)))
#+END_SRC

In addition you need to install the lsp server's executable in your system.
This can be done via npm:

#+BEGIN_SRC sh
  npm i -g dockerfile-language-server-nodejs
#+END_SRC

* Usage
** TRAMP access to docker containers
This relies on the [[https://github.com/emacs-pe/docker-tramp.el][docker-tramp]] package which uses =docker exec= available in
docker versions > 1.3.

=docker-tramp= adds a new prefix =/docker:= that you can use with ~SPC f f~,
this prefix allows to access your docker containers and also provides
auto-completion of the running containers.

* Key bindings

| Key binding | Description                                                       |
|-------------+-------------------------------------------------------------------|
| ~SPC m c b~ | build current buffer                                              |
| ~SPC m c B~ | build current buffer without cache                                |
| ~SPC a t d~ | entry point to interact with dockers, after that use ~?~ for help |
