06. Exercise: Build and Deploy

Exercise: Build and Deploy

Now it's finally time to build our container and check out the deployed app!

ND9991 C04 L03 A06 Code Example

Instructions

  • Run docker build --tag=api . from the directory containing your Dockerfile. If you want to use a different tag name, feel free to do so.
  • Wait for awhile as your Docker image is built (note: you are welcome to get a jump start on the next exercise, if desired, while this completes).
  • Use docker image ls to make sure your new Docker image is shown. You won't see the other containers in Noah's video - those are all of his other Docker images on his computer.
  • Run docker run -p 8000:5001 api. If you changed the tag name in the first step, make sure to replace api here with your tag name. Note above that the -p notes port 5001 from the Docker container (as specified in web.py for our flask app) is exposed on port 8000 on the host computer.
  • The container will tell us the Flask app is running on port 5001, but since we exposed port 8000 on our host to it, we will actually access the running app using port 8000. We haven't looked at Swagger documentation before here, but you can access it at http://localhost:8000 in your browser when the docker container is running. Note that Swagger is part of the implementation of this specific Flask app - if you make your own Flask app, Swagger won't be included unless you include it in your own code.
  • Test out one of the Swagger commands from the running containerized app.

More on Swagger

Swagger helps provide automated documentation for your APIs using the OpenAPI specifications.

Check out an example of a Swagger-based API here. Udacity actually uses Swagger for its internal-facing APIs!

Exposing Docker ports

Which of the following would allow you to look at a deployed Flask app that uses port 6001 by visiting http://localhost:8080?

SOLUTION: `docker run -p 8080:6001 my_app`

Code Example

  • Data Engineering API Example by Noah: LINK

The run_docker.py file in the video is included below:

#!/usr/bin/env bash

# Build image
docker build --tag=api .

# List docker images
docker image ls

# Run flask app
docker run -p 8000:5001 api