https://github.com/tsfoster/docker-tools
Functions for working with Docker and Docker Machine
https://github.com/tsfoster/docker-tools
Last synced: 20 days ago
JSON representation
Functions for working with Docker and Docker Machine
- Host: GitHub
- URL: https://github.com/tsfoster/docker-tools
- Owner: TSFoster
- License: mit
- Created: 2018-06-25T16:19:54.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-09-21T12:37:27.000Z (over 7 years ago)
- Last Synced: 2025-03-05T15:51:18.360Z (over 1 year ago)
- Language: Shell
- Size: 10.7 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Docker tools
Functions and commands for working with Docker and Docker Machine
## Install
With [fisherman](https://github.com/fisherman/fisherman):
```
fisher TSFoster/docker-tools
```
## Usage
- [`dmenv`](#dmenv)
- [`dmenvfile`](#dmenvfile)
- [`dbuild`](#dbuild)
### `dmenv`
```fish
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`
```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`:
1. Sets `$machineName` to `$DOCKER_MACHINE_NAME` or `localhost`
2. Sources `env/default.env` if it exists
3. Sources `env/[[MACHINE-DRIVER]].env` (e.g. `env/virtualbox.env`)
4. Sources `env/$DOCKER_MACHINE_NAME.env`
##### Example usage:
###### Filesystem:
- awesome-project/
- bin/
- deploy
- env/
- default.env
- virtualbox.env
- digitalocean.env
- awesome-project-staging.env
- awesome-project-prod.env
- stack.yml
###### `stack.yml`
```yml
[...]
deploy:
labels:
- "traefik.frontend.rule=Host:${hostName},www.${hostName}"
- "traefik.backend=${stackName}_rails"
[...]
environment:
RAILS_ENV: ${RAILS_ENV}
[...]
```
###### `bin/deploy`
```fish
#!/usr/bin/env fish
cd (dirname (status filename))/..
dmenvfile
docker stack deploy --compose-file=stack.yml awesome-project
```
###### `env/default.env`
```bash
stackName=awesomeproj
```
###### `env/virtualbox.env`
```bash
hostName=$stackName.$machineName
RAILS_ENV=development
```
###### `env/digitalocean.env`
```bash
hostName=awesome-project.com
```
###### `env/awesome-project-staging.env`
```bash
RAILS_ENV=production
hostName=staging.$hostName
```
###### `env/awesome-project-prod.env`
```bash
RAILS_ENV=production
```
###### To deploy
```fish
dmenv awesome-project-dev
/path/to/awesome-project/bin/deploy
```
1. Sets `$machineName` to `awesome-project-dev`
2. Sources `env/default.env`, sets `$stackName` to `awesomeproj`
3. Sources `env/virtualbox.env`, sets `$hostName` to `awesomeproj.awesome-project-dev` and `RAILS_ENV` to `development`
4. `env/awesome-project-dev.env` doesn’t exist, so skipped
5. Deploys stack.yml
### `dbuild`
`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.
```fish
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
```