-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
84 lines (63 loc) · 1.96 KB
/
Makefile
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
# Created by: George Corrêa de Araújo (george.gcac@gmail.com)
# ==================================================================
# environment variables
# ------------------------------------------------------------------
DOCKERFILE_CONTEXT = $(PWD)
DOCKERFILE = $(PWD)/Dockerfile
WORK_DIR = $(PWD)
RUN_STRING = bash start_here.sh
# ==================================================================
# Docker settings
# ------------------------------------------------------------------
CONTAINER_NAME = flask-$(USER)-$(shell echo $$STY | cut -d'.' -f2)
CONTAINER_FILE = flask-$(USER).tar
HOSTNAME = docker-$(shell hostname)
IMAGE_NAME = $(USER)/flask
PORT = 5000
USERNAME = $(USER)
WORK_PATH = /work
RUN_CONFIG_STRING = --name $(CONTAINER_NAME) --hostname $(HOSTNAME) --rm -it --dns 8.8.8.8 \
--userns=host --ipc=host --ulimit memlock=-1 -w $(WORK_PATH) -p $(PORT):5000 $(IMAGE_NAME):latest
WORK_MOUNT_STRING = --mount type=bind,source=$(WORK_DIR),target=$(WORK_PATH)
# ==================================================================
# Make commands
# ------------------------------------------------------------------
# Build image
build:
docker build \
--build-arg GROUPID=$(shell id -g) \
--build-arg GROUPNAME=$(shell id -gn) \
--build-arg USERID=$(shell id -u) \
--build-arg USERNAME=$(USERNAME) \
-f $(DOCKERFILE) \
--pull --no-cache --force-rm \
-t $(IMAGE_NAME) \
$(DOCKERFILE_CONTEXT)
# Remove the image
clean:
docker rmi $(IMAGE_NAME)
# Load image from file
load:
docker load -i $(CONTAINER_FILE)
# Kill running container
kill:
docker kill $(CONTAINER_NAME)
# Run RUN_STRING inside container
run:
docker run \
$(WORK_MOUNT_STRING) \
$(RUN_CONFIG_STRING) \
$(RUN_STRING)
# Save image to file
save:
docker save -o $(CONTAINER_FILE) $(IMAGE_NAME)
# Start container by opening shell
start:
docker run \
$(WORK_MOUNT_STRING) \
$(RUN_CONFIG_STRING)
# Test image by printing some info
test:
docker run \
$(RUN_CONFIG_STRING) \
python -V