This is set of bash scripts to help manage developers environment based on Docker's containers. Assumption is that you have a set of common developers tools already installed on you host machine and you just want some additional ones for secific project.
For every environment you have to create configuration with list of images and commands to run in containers run from this images. When a command is first time used, contaner is created and from now this command is run as docker exec
in the created container. After work on project is done, you can stop all containers with one command.
Docker runners are small script which run docker container with specific options, should be located in folder $HOME/.dockenv
or $XDG_CONFIG_HOME/dockenv
. For example:
docker run --detach --rm -it \
--user $(id -u):$(id -g) \
-v $(pwd):$(pwd) \
-w $(pwd) \
-v /tmp:/tmp \
-v /usr/local/share/nvim:/usr/local/share/nvim:ro \
-v $HOME/.local/share/nvim:$HOME/.local/share/nvim:ro \
--name $1 \
vim-tools /bin/sh > /dev/null
run --detach --rm -it
- option makes container running in background, removing after stopping and allow to use pseudo terminal if there is need for it.
--user $(id -u):$(id -g)
- run container as original user, help managing ownership of files created, modified inside container
-v $(pwd):$(pwd) -w $(pwd)
- mount project root folder to container and make it working directory
--name $1 image:tag /bin/sh > /dev/null
- name is autogenerated, image:tag is what kind of image we want to use for this container
More examples are in docker-runners folder.
- GNU/Linux
- Bash
- Docker
- direnv
- yq >= 3.0.0
Clone repository git clone --depth 1 https://github.com/mandos/dockenv.git /destination-folder
Add bin folder from repository to your PATH PATH=/destination-folder/bin:$PATH
in your .bashrc or .zshrc file
Add use_dockenv()
function to .direnv file
use_dockenv() {
export DOCKENV_ROOT=$PWD
dockenv-start
PATH_add "${DOCKENV_ROOT}/.dockenv/bin"
}
Create one or more docker runners in folder $HOME/.dockenv
or $XDG_CONFIG_HOME/dockenv
.
In root project add .dockenv.yaml file with all docker runners and command which will be used with it. For example:
vim-tools:
cmd:
- vint
- vim-language-server
terraform-tools:
cmd:
- terraform
This file will use two docker runners, using vint
and vim-language-server
will be redirected to vim-tools
container and using terraform
to terraform-tools
.
In root project project folder initialize direnv and add there use_dockenv
method. After initialization of direnv there should be created .direnv/bin
folder with all overrided commands.
Tested manually on:
- Ubuntu 16.04
- Bash 4.3.48
- direnv 2.23.1
- yq 3.4.1
- Docker 19.03.13
This project is licensed under terms of MIT licence.