-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
77 lines (59 loc) · 2.11 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
# escape=\ (backslash)
# Setting escape character to \ (that's the default anyway) ^
# Parser directives have to come at the begining.
# format: FROM:TAG
FROM python:2.7
# Labels are being used to add metadata to an image.
# Docker recommends combining labels into a single LABEL
LABEL version="1.0.0"\
"description"="Notes and docker reference/cheatsheet."
# Create a new dir
RUN mkdir /scripts
# Copy print.bash to /scripts/
COPY *.py /scripts/
# Add does the same
#a Add also untar files and can download from urls
ADD dummy_flask.py /home/
# create a new mount for it
VOLUME /scripts
RUN df -h
# install pip and flask
RUN apt-get -y update && apt-get install -y python-pip
RUN ["pip", "install", "flask"]
# We can also use SHELL.
# The last SHELL command will override all earlier ones (i.e. this will break).
#SHELL ["pip", "install", "flask"]
# when running docker we can pass argument --build-arg user=<username> in built time
ARG user
# Run this on a later stage (on build)
ONBUILD RUN touch /tmp/test
# /tmp/test will not be created until later.
RUN ["ls", "/tmp/"]
# Set DUMMY_DIR to /root
ENV DUMMY_DIR /scripts
# If var doesn't exist then set otherwise keep value
ENV USER_NAME ${user:-"flask"}
# Informs Docker that container will listen to port 8000
# still need to run the application using -p for the port to be reachable on the host.
EXPOSE 8000
# Create a new user and set user to flask
RUN useradd --shell /bin/bash --uid 22 $USER_NAME
USER $USER_NAME
#USER 22
RUN whoami
# Change working dir to /scripts
# If the WORKDIR doesn’t exist, it will be created
WORKDIR $DUMMY_DIR
# make sure we are in /scripts
RUN pwd
# There can only be one CMD instruction. If more than one CMD then last one
# Better way for this is to use ENTRYPOINT and CMD for defaults
# Run a dummy flask
ENTRYPOINT ["./dummy_flask.py"]
CMD ["8000"]
# Setting healcheck for container
# The output of the check can be seen when inspecting the container under health
# To disable all HEALTHCHECKs add HEALTHCHECK NONE
HEALTHCHECK --interval=5s --timeout=1s --retries=2 CMD curl http://127.0.0.1:8000/
# Setting stop signale
STOPSIGNAL SIGKILL