-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.bashrc_docker
More file actions
178 lines (145 loc) · 5.68 KB
/
.bashrc_docker
File metadata and controls
178 lines (145 loc) · 5.68 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# Docker
# List all containers (only IDs): docker ps -aq
# Stop all running containers.: docker stop $(docker ps -aq)
# Remove all containers: docker rm $(docker ps -aq)
# Remove all images: docker rmi $(docker images -q)
alias dps="showCommand docker ps"
alias dpsa="showCommand docker ps -a"
alias di="showCommand docker images"
alias dip="docker inspect -f '{{ .NetworkSettings.IPAddress }}'"
# List all containers (only IDs): docker ps -aq
alias dstop='confirmCommand docker stop $(docker ps -aq)'
alias drm='confirmCommand docker rm $(docker ps -aq)'
alias drmi='confirmCommand docker rmi $(docker images -q)'
alias dlog="showCommand docker logs -f"
function getContainerID() {
repo = ${PWD##*/}
local containerID=`docker ps | grep $repo | cut -c1-6`
echo "$containerID"
}
export -f getContainerID
function dclean() {
local containerID=$1
if [ -z $1 ]; then
containerID=`getContainerID`
fi
showCommand docker stop $containerID
showCommand docker rm $containerID
}
export -f dclean
function dlog() {
local containerID=$1
if [ -z $1 ]; then
containerID=`getContainerID`
fi
showCommand docker logs -f $containerID
}
### Mongo container setup ###
# $ docker create --name mongo-test -p <port>:27017 mongo:latest --storageEngine wiredTiger
# $ docker create --name mongo -p 27017:27017 -v ~/DataStore/mongo:/var/lib/mongo mongo:latest --storageEngine wiredTiger
alias mongo='docker exec -it mongo mongo'
### Postgres container setup and run (multiple steps) ###
# $ docker run --name postgres -e POSTGRES_PASSWORD=mysecretpassword -v ~/DataStore/postgresql:/var/lib/postgresql/data -p 5432:5432 -d postgres:latest
# $ docker create --name postgres -e POSTGRES_PASSWORD=mysecretpassword -v ~/DataStore/postgresql:/var/lib/postgresql/data -p 5432:5432 -d postgres:latest
#
# -------------------------------------------------
### postgres docker base image
# $ docker exec -it postgres bash
# # Now we have root access to the container. Notice the container ID in the command prompt. To access postgres you need to change to user ‘postgres’ and then run psql. To exit psql, type \q
# # ## su postgres
# # ## psql
# # ## \conninfo
# # ## \q
function postgres() {
local db=$1
if [ -z $1 ]; then
db='testdb'
fi
showCommand docker exec -it postgres psql -d $db -U postgres
}
### Cassandra container setup ###
# $ docker pull cassandra:latest
# $ docker run --name cassandra-v3 -p 9042:9042 -d -v ~/DataStore/cassandra:/var/lib/cassandra cassandra:3
# $ docker exec -it cassandra-v3 cqlsh
# -------------------------------------------------
### Create container from image that is already downloaded
# $ docker create --name cassandra-v3 -p <port>:9042 -v ~/DataStore/cassandra:/var/lib/cassandra cassandra:3
# $ docker start cassandra-v3
# To set up a cluster: https://hub.docker.com/r/bitnami/cassandra/
# -------------------------------------------------
### To set up Cassandra to auto restart on a reboot or docker restart
# $ docker update --restart={no,on-failure,unless-stopped,always} cassandra-v3
# -------------------------------------------------
### All on one line to pull and run in detached mode
# $ docker run --name cassandra-v3 --restart={no,on-failure,unless-stopped,always} -p 9042:9042 -v ~/DataStore/cassandra:/var/lib/cassandra -d cassandra:3
function cassandra() {
status=false
help=false
casVersion="cassandra-v3"
env="DEV"
userCommand=""
userPassword=""
project=$PROJECT
OPTIND=1
while getopts ":he:p:sv:" opt; do
case $opt in
p) project=$OPTARG
case $project in
Spike)
name='spike'
;;
*) help=true
;;
esac
;;
e) env=$OPTARG
;;
s) status=true
;;
v) casVersion="cassandra-$OPTARG"
;;
h|\?) help=true
;;
:) echo "Option -$OPTARG requires an argument"
return
;;
esac
done
shift $((OPTIND-1))
case $env in
DEV|dev) eval user='$'"${name}User"
eval password='$'"${name}Password"
eval ip='$'"${name}IPAddress"
# This copies the password into the clipboard to be pasted with cmd-v
echo $password | pbcopy
[[ -n $user ]] && userCommand="-p $user"
[[ -n $password ]] && userPassword="-u $password"
;;
*) help=true
;;
esac
if $help; then
echo "************************************************************"
echo "Usage: cassandra [<options>]"
echo "-p - project name"
echo "-e < _DEV_ > - environment"
echo "-s - get status of cassandra"
echo "-v <version> ex: v3 - which version of cassandra to use (must have an image started)"
echo "-h - help"
echo "************************************************************"
echo "To create an image: "
echo "docker create --name cassandra-v3 -p <local-port>:9042 -v ~/DataStore/cassandra:/var/lib/cassandra cassandra:3"
echo "docker start cassandra-v3"
echo "************************************************************"
return
fi
# can we put this in as an option with a ~10 second sleep after
# docker start $casVersion
if $status; then
showCommand docker exec -it $casVersion nodetool -h $ip status
return
fi
showCommand docker exec -it $casVersion cqlsh --no-color $userCommand $userPassword $ip
}
export -f cassandra
# EOF