Functions and commands for working with Docker and Docker Machine
With fisherman:
fisher TSFoster/docker-tools
dmenv --help # Print help
dmenv MACHINE_NAME # Run "eval (docker-machine env MACHINE_NAME --shell=fish)"
dmenv # Run "eval (docker-machine env --unset --shell=fish)"
dmenvfile --help # Print help
dmenvfile # Source files related to $DOCKER_MACHINE_NAME in ./env directory
dmenvfile --print --dir=other/env/path --unexport --no-global
Sources posix-style env files, in order, related to the current $DOCKER_MACHINE_NAME
:
- Sets
$machineName
to$DOCKER_MACHINE_NAME
orlocalhost
- Sources
env/default.env
if it exists - Sources
env/[[MACHINE-DRIVER]].env
(e.g.env/virtualbox.env
) - Sources
env/$DOCKER_MACHINE_NAME.env
- awesome-project/
- bin/
- deploy
- env/
- default.env
- virtualbox.env
- digitalocean.env
- awesome-project-staging.env
- awesome-project-prod.env
- stack.yml
- bin/
[...]
deploy:
labels:
- "traefik.frontend.rule=Host:${hostName},www.${hostName}"
- "traefik.backend=${stackName}_rails"
[...]
environment:
RAILS_ENV: ${RAILS_ENV}
[...]
#!/usr/bin/env fish
cd (dirname (status filename))/..
dmenvfile
docker stack deploy --compose-file=stack.yml awesome-project
stackName=awesomeproj
hostName=$stackName.$machineName
RAILS_ENV=development
hostName=awesome-project.com
RAILS_ENV=production
hostName=staging.$hostName
RAILS_ENV=production
dmenv awesome-project-dev
/path/to/awesome-project/bin/deploy
- Sets
$machineName
toawesome-project-dev
- Sources
env/default.env
, sets$stackName
toawesomeproj
- Sources
env/virtualbox.env
, sets$hostName
toawesomeproj.awesome-project-dev
andRAILS_ENV
todevelopment
env/awesome-project-dev.env
doesn’t exist, so skipped- Deploys stack.yml
dbuild
will source an env file before trying to build and optionally push the images specified. It follows some basic rules for finding the env file and the appropriate build directories, but the settings can be overwritten.
dbuild --help # Print help
dbuild backup database nginx # Build images defined in ./backup/Dockerfile ./database/Dockerfile and ./nginx/Dockerfile, sourcing ./env/build.env first
dbuild --force-push --env-file=./buildSettings.env --registry-url=registry.gitlab.com/tsfoster/awesome-project reverseproxy rails database
set -x dbuildRegistryUrl tsfoster
echo dbuildValidImages=reverseproxy api-server > env/build.env
dbuild --no-push reverseproxy --build-path=traefik api-server --build-path=drupal incorrect-image-name --build-path=incorrect-image-name