-
Notifications
You must be signed in to change notification settings - Fork 34
/
docker-ln
executable file
·33 lines (29 loc) · 1.19 KB
/
docker-ln
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash
usage() {
bin=$(basename $0)
echo >&2 "Usage: $bin [-r] service [link-name]"
echo >&2
echo >&2 "Wrapper around docker/docker-compose to symlink uppermost"
echo >&2 " merged overlayfs layer of a running service/container in a compose setup."
echo >&2 "Such symlink allows to copy/edit stuff to/from running container easily."
echo >&2 "Default symlink name will be underscore + service-name, e.g. _mysvc"
echo >&2 "Such paths are likely to change on restarts, re-run the tool to fix them."
echo >&2
echo >&2 "Options:"
echo >&2 " -r -- make relative symlink, as in 'ln -rs'."
exit ${1:-0}
}
rel= svc= link=
[[ "$1" = -h || "$1" = --help ]] && usage
[[ "$1" = -r ]] && { rel=t; shift; }
[[ "$#" -lt 1 || "$#" -gt 2 ]] && usage || svc=$1 link=$2
set -eo pipefail
cid=$(docker-compose ps -q "$svc")
[[ -n "$cid" ]] || { echo >&2 "ERROR: not dc-ps id for service '$svc'"; exit 1; }
dst=$(docker inspect -f '{{.GraphDriver.Data.MergedDir}}' "$cid")
[[ -n "$dst" ]] || { echo >&2 "ERROR: not d-inspect dir for container '$svc' [ $cid ]"; exit 1; }
[[ -n "$link" ]] || link="_$svc"
[[ ! -L "$link" ]] || rm -f "$link"
ln_opts=()
[[ -z "$rel" ]] || ln_opts+=( -r )
ln "${ln_opts[@]}" -s "$dst" "$link"