forked from luiselizondo/docker-mysql-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dmysql-server
executable file
·51 lines (38 loc) · 1.66 KB
/
dmysql-server
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
#!/usr/bin/env python
import sys
from subprocess import call
import argparse
def createVolume(containerVolumeName):
''' Create a data only container
'''
print 'Creating the container using the volumes-from strategy. Using container {container} as the container name'.format(container=containerVolumeName)
call("docker run -v /var/lib/mysql --name "+ containerVolumeName+" busybox true", shell=True)
return
def runContainer(containerName, rootPassword, hasVolume=False):
''' Creates the container
'''
if hasVolume:
# Create the container name variable
containerVolumeName = containerName.upper() + '_DATA'
# Create data container
createVolume(containerVolumeName)
call('docker run --volumes-from ' + containerVolumeName + ' --name ' + containerName + ' -e MYSQL_ROOT_PASSWORD="' + rootPassword + '" -d mysql', shell=True)
else:
call('docker run --name ' + containerName + ' -e MYSQL_ROOT_PASSWORD="' + rootPassword + '" -d mysql', shell=True)
return
def main():
parser = argparse.ArgumentParser(
description="Creates a new MySQL container using the mysql image",
prog="dmysql-server")
parser.add_argument("containerName", help="The name of the mysql container to create")
parser.add_argument("rootPassword", help="The root password to define when creating the container")
parser.add_argument("--with-volume", help="Creates a data-only container", action='store_true')
args = parser.parse_args()
# If there's a volume
if args.with_volume:
runContainer(containerName=args.containerName, rootPassword=args.rootPassword, hasVolume=True)
else:
runContainer(containerName=args.containerName, rootPassword=args.rootPassword)
return
# Execute main
main()