-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDockerfile
executable file
·79 lines (59 loc) · 2.26 KB
/
Dockerfile
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
## TO BUILD IMAGE:
# docker build -t ml .
## TO RUN IMAGE (ENVIRONMENTAL VARIABLES DECLARED ABOVE)
# docker run -itp 8080:8080 --memory=1g ml
## TO RUN IMAGE (OVERRIDE ENVIRONMENTAL VARIABLES DECLARED ABOVE)
# docker run -itp 8080:8080 --memory=1g --env MODEL_FILE="models/ml_classifier.pkl" ml
## TO SAVE THE IMAGE
# docker save ml -o ml.rar
## TO IMPORT THE IMAGE
# docker load -i ml.rar
FROM python:3.9-slim
# From pytorch/pytorch
#############################
# INSTALL PYTHON DEPENDENCIES
#############################
# install git for pip install git+https://
# RUN apt-get -o Acquire::Max-FutureTime=100000 update \
# && apt-get install -y --no-install-recommends build-essential git
# create a virtual environment
# RUN python -m venv /opt/venv
# ENV PATH="/opt/venv/bin:$PATH"
# copy and install python requirements + ember from github
COPY docker-requirements.txt .
# RUN pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
RUN pip install torch torchvision torchaudio
RUN pip install --no-cache-dir -r docker-requirements.txt
#############################
# REBASE & DEPLOY CODE
#############################
# rebase to make a smaller image
# FROM python:3.9-slim
# # required libgomp1 for ember
# RUN apt-get -o Acquire::Max-FutureTime=100000 update \
# && apt-get -y --no-install-recommends install \
# libgomp1 \
# && rm -rf /var/lib/apt/lists/*
# # copy python virtual env (all dependencies) from previous image
# COPY --from=0 /opt/venv /opt/venv
# change working directory
WORKDIR /opt/defender/
# copy defender code to /opt/defender/defender
COPY docker /opt/defender/defender
#############################
# SETUP ENVIRONMENT
#############################
# open port 8080
EXPOSE 8080
# add a defender user and switch user
# RUN groupadd -r defender && useradd --no-log-init -r -g defender defender
# USER defender
# update environmental variables
# ENV PATH="/opt/venv/bin:$PATH"
# ENV PYTHONPATH="/opt/defender"
# one may tune model file / threshold / name via environmental variables
# ENV MODEL_FILE models/ml_classifier.pkl
#############################
# RUN CODE
#############################
CMD python -m defender > /dev/null 2>&1