Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll

- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
Developers use configuration files to customize the tools they use every day. Likewise, Docker looks for a Dockerfile for instructions on how it should build an image. In this stage, we're going to learn about all the instructions you can include in a Dockerfile so that your image is configured just the way you want it.
Here are the contents of the files used in the video:
Dockerfile
# Base Image
FROM ubuntu:latest
# Commands to run to install dependencies
RUN apt-get update -y
RUN apt-get install -y python3
# When you pass commands to the container, what should interpret them
ENTRYPOINT ["python3"]
# Command to run when the container starts
CMD ["app.py"]
# Working directory
WORKDIR /app
# Copy apps from the local folder to the Docker container
COPY app.py app.py
COPY alternate.py alternate.py
# Make port available
EXPOSE 8080
app.py
#!/usr/bin/env python
from http.server import BaseHTTPRequestHandler, HTTPServer
class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header('Content-type','text/html')
self.end_headers()
self.wfile.write(bytes("Hello from Python!", "utf8"))
return
def run():
httpd = HTTPServer(('0.0.0.0', 8080), testHTTPServer_RequestHandler)
httpd.serve_forever()
run()
alternate.py
#!/usr/bin/env python
from http.server import BaseHTTPRequestHandler, HTTPServer
class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header('Content-type','text/html')
self.end_headers()
self.wfile.write(bytes("This is an alternate app!", "utf8"))
return
def run():
httpd = HTTPServer(('0.0.0.0', 8080), testHTTPServer_RequestHandler)
httpd.serve_forever()
run()
Further Reading
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
PLUS
Rhett Herring
Courses Plus Student 11,023 Points1 Answer
-
PLUS
Michael Lau
Courses Plus Student 26,298 Points0 Answers
-
Tony Brackins
28,766 Points0 Answers
-
Francisco Ortiz
2,673 Points0 Answers
-
Denis Frunz
15,929 Points1 Answer
-
lio1986
19,649 Points1 Answer
-
paz schori
980 Points0 Answers
-
Thomas Le
8,317 Points1 Answer
View all discussions for this video
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up