-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathdocker_handy.sh
68 lines (61 loc) · 1.7 KB
/
docker_handy.sh
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
################################################################################
#
# Handy Little Docker shortcuts.
#
# This file contains a collection of bash functions that can be used to
# reduce the typing associated with controlling Docker operations.
# For example drmac (docker rm all containers) will remove all of the
# dontainer in the docker engine.
#
# - Source this file into your working shell
# - Read this file to see the commands
# - And then use the functions defined herein
# do the Docker things in your working shell.
#
#------------------------------------------------------------------------------
# - - - - - - - - - - - - - - - - - - - -
# Stop all running containers
#
function dhalt() {
docker stop $(docker ps -aq);
}
# - - - - - - - - - - - - - - - - - - - -
# Remove all containers
#
function drmac(){
docker rm -f $(docker ps -aq);
}
# - - - - - - - - - - - - - - - - - - - -
# Remove all images
#
function drmai(){
docker rmi -f $(docker images -q);
}
# - - - - - - - - - - - - - - - - - - - -
# List all containers (only IDs)
#
function dlist(){
docker ps -aq;
}
# - - - - - - - - - - - - - - - - - - - -
# Interactive Login Shell
#
# Uses the first argument as the id of the running container.
#
function dlogin(){
docker exec -ti $1 bash;
}
# - - - - - - - - - - - - - - - - - - - -
# stop, cleanup container and image, build, run, login interactive shell
#
function dscbrl() {
package=$1;
tag=`echo "${package}" | tr '[:upper:]' '[:lower:]'`
docker container stop ${tag}
docker rm $(docker ps -aq)
docker rmi ${tag}
docker build -t ${tag} ${package}
docker run --name ${tag} -d -p 8080:8080 ${tag}
docker exec -ti ${tag} bash
}