The Dockerfile contained in this repository may be used to create a container that provides a vim/tmux based development environment. It uses GitHub to retrieve public keys to facilitate ssh connections.
Disclaimer: This Dockerfile and referenced configuration files represent my own development environment, which continues to evolve. Use at your own risk.
#####Background
Don Petersen's 'dev-container-base' (link below) was a primary source, and much credit and appreciation goes to him. (Note he uses different vim plugins as well as additional tools such as homesick and direnv, some of which I may adopt in the future.) Following are links to his write-up and repository:
In addition, the following references were also helpful:
- How to use docker on OS X: the missing guide
- boot2docker-fwd
- Docker blurs the line between SAAS and selfhosted apps
- Build a zen command-line environment with git tmux oh-my-zsh and docker
Docker requires linux so to use on OS X or Windows a (lightweight) linux VM must be used. When running on OS X or windows, you may use either Vagrant or 'boot2docker'. I currently use boot2docker, so the following is specific to using boot2docker on OS X.
boot2docker may be installed using a package installer or brew. The package installer will install Docker, the boot2docker ISO, the boot2docker manage tool, and VirtualBox. This will also handle creating an ssh key pair (which may need to be done manually if installing via brew).
If using brew:
$ brew tap phinze/homebrew-cask
$ brew install brew-cask
$ brew cask install virtualbox
$ brew install docker
$ brew install boot2docker
$ boot2docker init
To start the VM:
$ boot2docker up
The above will indicate the DOCKER_HOST environment variable must be set if you haven't done this previously. (If you already use the chasdev/config-files repository to manage your dot-files, this will be set already.)
export DOCKER_HOST=tcp://192.168.59.103:2376
$ git clone [email protected]:chasdev/dev-env.git
$ cd dev-env
#####Building the image and running a container
To build the image:
$ docker build -t chasdev/dev-env .
Next we'll start the container. The following mounts '~/working' as '/working' within the container, as I keep all of my code under this directory. This container allows multiple users who are identified in the comma-deliminated environment variable set below. These users must be GitHub users, and their public keys will be retrieved and added to the container. (This uses a ssh_key_adder.rb ruby script developed by Don Petersen.)
docker run \
-d -e AUTHORIZED_GH_USERS="chasdev" \
-p 0.0.0.0:12345:22 \
-v /Users/chas/working:/working \
chasdev/dev-env:latest
Since this container is used as a 'development environment', it uses ssh (which is not a best practice for 'service' containers). Most of your containers should use 'nsenter' in lieu of ssh.
To facilitate connecting to a running container over ssh, we'll set an alias by adding the following to '~/.ssh/config' file. (If using boot2docker, the 'IP or hostname' is that of the vm and not the host. You can determine this IP by using: 'boot2docker ip').
Host devbox
HostName <YOUR IP OR HOSTNAME>
Port <YOUR MAPPED SSH PORT FROM ABOVE>
User root
ForwardAgent true
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
Now we can connect using:
ssh devbox
Vundle is used to install all vim plugins listed in the .vimrc file (from 'https://github.com/chasdev/config-files'), and the Dockerfile includes steps to build the necessary native libraries for these plugins. Unlike previous versions of this container, no manual configuration is necessary to use vim, tmux, or wemux.
The container should be usable, providing a command-line centric development environment comprised of bash, vim, tmux, and git. This container may be extended to provide a complete development environment with language-specific support (e.g., node.js, golang, Java/groovy, Scala, etc.). My dev-env-node container is an example.