**CIS 1920 Worksheet 5 🐳**
**Due Friday 4/21 11:59 pm EST**
(#) Objectives - Course feedback - **Bonus**: familiarization with containerization and deployment concepts via Docker (#) Starter files - [ws5.md](ws5.md) - [Dockerfile](Dockerfile) - [requirements.txt](requirements.txt) (#) Task 1: Course feedback [2 points] In the provided in the starter file, please respond to the following questions: 1. What are the most significant things you learned from the course? Did you find the material valuable -- why or why not? Here are the six homework assignments for this semester, as well as the associated topics we covered: ~~~~ HW 1: Tries (Python basics) HW 2: BSTs (Classes, recursion, exception handling) HW 3: Reddit (Modules and unit tests) HW 4: Machine learning (Scientific computing) HW 5: Deep learning (Jupyter notebooks + web scraping) HW 6: Bird not bird (Flask) ~~~~ 2. What was your favorite homework assignment? What did you like about it? 3. What was your least favorite homework assignment? How could it have been improved? 4. Please provide any general feedback so we can improve the course for future semesters. Are there changes you would like to see made to the course structure? If you don't have any suggestions, no worries :) (#) Task 2: (BONUS) Docker deployment [1 point] For this task, you'll deploy your HW 6 flask app as a Docker image. Since installing Docker on your local machine can be an involved process, we'll use the official playground provided by Docker to do so: https://labs.play-with-docker.com/ First, create a free Docker account at: https://hub.docker.com Then navigate to https://labs.play-with-docker.com/ and log in with your credentials. From here, you'll see a basic UI with the ability to create new Docker server instances. Click "ADD NEW INSTANCE." You'll then be greeted with a terminal prompt as well as some information about the server that's been allocated to you: ![](ws5_docker_playground.png) This server instance already has Docker installed, so we can use it to build the Docker image for us. But first, we'll need to write the Dockerfile. Use the starter files provided and go through the process of copying over required files and installing Python requirements like we did in the Week 14 lecture. Note that we do not need to specify the `EXPOSE` command because our flask app will by default run on port 5000. !!! TIP Make sure to use the `requirements.txt` we provide as a starter file, as it contains a "slim" version of torch to make the container more portable. We'll also need to make a small change to the `app.run()` call in the `__main__` block of our HW 6 server, to allow for all incoming web traffic: ~~~~python if __name__ == "__main__": # 0.0.0.0 tells the server to listen on all network interfaces, including the rest of the web app.run(port=5000, debug=False, host='0.0.0.0') ~~~~ Once your Dockerfile is completed and you've made the change to your `hw6.py` file, we'll copy all of the HW 6 files into the Docker instance. Copy the IP address provided in the `ssh` text box in the Docker playground, making sure to remove the `ssh ` at the beginning of the command. Then, using that IP address, copy your HW 6 files and your Dockerfile into the Docker server instance: ~~~~~bash # copy Dockerfile up to the server, make sure to include # the :~/ at the end of the IP address! # Note: your server instance will have a different IP address, # this is just an example. $ scp Dockerfile ip172-18-0-19-c6k0iifnjsv0009gnud0@direct.labs.play-with-docker.com:~/ Connecting to 52.149.144.189:8022 Dockerfile 100% 496 9.8KB/s 00:00 # copy the requirements.txt file as well $ scp requirements.txt ip172-18-0-19-c6k0iifnjsv0009gnud0@direct.labs.play-with-docker.com:~/ Connecting to 52.149.144.189:8022 requirements.txt 100% 62 1.3KB/s 00:00 # copy any other HW 6 files needed up to the # server, using the same syntax. For example: $ scp -r templates ip172-18-0-19-c6k0iifnjsv0009gnud0@direct.labs.play-with-docker.com:~/ Connecting to 52.149.144.189:8022 result_template.html 100% 340 8.6KB/s 00:00 upload_template.html 100% 551 12.5KB/s 00:00 $ scp hw6.py ... ~~~~~ Now, go back do your browser with the Docker playground open, and double check you have all of the files needed uploaded to the instance by running `ls`: ![](ws5_docker_playground_ls.png) Now, we can create our Docker image! Just like in lecture, run `docker build` with an appropriate tag name: ~~~~bash $ docker build -t bird-not-bird . Sending build context to Docker daemon 47.26MB Step 1/10 : FROM python:3.7-slim 3.7-slim: Pulling from library/python ... Successfully built 8453e5848562 Successfully tagged bird-not-bird:latest ~~~~ If all goes well, you'll see a similar success message to the one indicated above. Now, let's run our Flask app! Since by default we open port 5000 for the server, we'll need to tell Docker that we want to open that port on the container with the `-p` flag: ~~~~bash docker run -p 5000:5000 bird-not-bird ~~~~ You should now see a new button in the playground UI that has a link to the port we just opened: ![](ws5_docker_playground_port.png) If you don't see the port 5000 appear, you can manually open the port by clicking "Open Port" and typing in port 5000. If you've copied all the flask files over correctly, you should now see your flask server interface, now available on the open web! ![](ws5_docker_playground_running.png) Take a screenshot of your running server, with the URL bar visible so we can verify that it is running in Docker playground. (#) Submission Once you've completed the course feedback, submit `ws5.md` to Gradescope. If you've completed the bonus section on Docker, also submit: - your `Dockerfile` - your screenshot of your HW 6 app running in Docker playground That's it, worksheet 5 complete!