Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
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 upRelated 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