-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathembark.sh
executable file
·52 lines (42 loc) · 1.41 KB
/
embark.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
#!/bin/bash
# https://github.com/dubniczky/Shell-Utilities
# Build the local Dockerfile and quick run it with customizable parameters
name="tempimage:latest"
port="8000:8000"
# Check for help
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "Build the local Dockerfile and quick run it with customizable parameters"
echo ""
echo "Usage: embark [container_name?] [ports?] [args...]"
echo " container_name: The name and tag of the image to build. Default: user/folder"
echo " ports: The source and destination ports to expose. Default: $port"
echo " args: All subsequent parameters will be passed to the docker run command."
echo ""
echo "Examples:"
echo " embark - build and run dockerfile with default name and port"
echo " embark myimage:latest 80:80 - build and run dockerfile with custom name"
echo " embark myimage:latest 80:80 -d - build and run dockerfile with custom name and daemon mode"
exit 0
fi
# Assemble default container name
directory=${PWD##*/}
user=$(whoami)
name="$user/$directory:latest"
# Assign parameters
if [ ! -z $1 ]; then
name=$1
fi
if [ ! -z $2 ]; then
port=$2
fi
echo "Container name: $name"
echo "Container port: $port"
# Build the container
if [ -f "Dockerfile" ]; then
docker build -t $name .
else
echo "No Dockerfile found in current directory."
exit 1
fi
# Run the container
docker run -p $port --rm "${@:3}" $name