This document just conventionalizes some practices laid out in
18F/calc#1406, making it a bit easier to run
commands in docker containers without having to constantly prefix
them with e.g. docker-compose run app.
Using this convention requires first modifying one's .bashrc:
# Make project-specific docker shortcuts work
export PATH="./.docker-bin:$PATH"You'll also want to add .docker-bin to your global gitignore.
First run git config --get core.excludesfile. If
that outputs a filename, you'll want to edit that file. Otherwise, you'll
want to run:
touch ~/.gitignore_global
git config --global core.excludesfile ~/.gitignore_globalNow edit your global gitignore file and add the line .docker-bin to it.
For every docker-based project you want to create shortcuts for, create
a directory called .docker-bin in the project's root directory. Populate
it with scripts that just shell out to docker-compose.
For instance, if you frequently use jest in your project's app container,
you can create the following script at ./docker-bin/jest:
#! /bin/sh
docker-compose run --rm app jest $*Make this script executable via chmod +x .docker-bin/jest.
Now you can use jest from the root directory of your project's repository,
and it will be "proxied" to your app container.
Adam Kendall noted that, if all your main containers across projects are
called the same thing, it might be easier to just do a simple prefix
with alias. For example, alias d='docker-compose run --rm app $*'
would allow you to do d anycommand anyargs, which obviates the
need for modifying one's PATH, global gitignore, and separate bin
files for every tool.