Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
# Use an official Python runtime as a parent image
FROM python:2.7-slim

ARG PORT
ENV PORT ${PORT:-8080}

# Define environment variable
ARG NAME
ENV NAME ${NAME:-World}

# Set the working directory to /app
WORKDIR /app

# Copy the current directory contents into the container at /app
ADD . /app
ADD install-reqs.sh requirements.txt /app/

# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt
# RUN pip install --trusted-host pypi.python.org -r requirements.txt
RUN bash -c "/app/install-reqs.sh"

# Make port 80 available to the world outside this container
EXPOSE 80

# Define environment variable
ENV NAME World
# Make port available to the world outside this container
EXPOSE ${PORT}

# Run app.py when the container launches
CMD ["python", "app.py"]

# Copy the current directory contents into the container at /app
ADD . /app
8 changes: 7 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

app = Flask(__name__)

def parse_int(s, val=None):
if s.isdigit():
return int(s, 10)
else:
return val

@app.route("/")
def hello():
try:
Expand All @@ -21,5 +27,5 @@ def hello():
return html.format(name=os.getenv("NAME", "world"), hostname=socket.gethostname(), visits=visits)

if __name__ == "__main__":
app.run(host='0.0.0.0', port=8080)
app.run(host='0.0.0.0', port=parse_int(os.getenv("PORT", 8080)))

5 changes: 5 additions & 0 deletions install-reqs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

set -eo pipefail;

pip install --trusted-host pypi.python.org -r requirements.txt