Key Word(s): Docker



APCOMP 295 Advanced Practical Data Science

Demo 1 - Getting started with Docker

Harvard University
Fall 2020
Instructors: Pavlos Protopapas


Installing Docker Desktop

  1. Install Docker Desktop. Use one of the links below to download the proper Docker application depending on your operating system.
  2. Once installed run the docker desktop.
  3. Open a Terminal window and type docker run hello-world to make sure Docker is installed properly.

[If you are working on a Windows machine, we are aware of some issues with downloading and installing Docker Desktop depending on your version of Windows.]


Building a Dockerfile for a Linux container¶

  1. Create a lecture2/ directory. Download the syllabus.md file from our web page to your lecture2/ directory.
  • Note: Use curl https://raw.githubusercontent.com/Harvard-IACS/2020F-AC295/master/content/pages/syllabus.md -o syllabus.md to download the syllabus.md file from the web-page.
  • Do not copy and paste into a file on your computer. This will give different character counts than if you download it.
  1. Open a new file called Dockerfile in a text editor. Save the file to your lecture2/ directory.
  2. Copy and paste the following lines into your Dockerfile.
# The following line will download the latest Ubuntu Docker image
# to use as a foundation for building our own Docker image.
FROM ubuntu:latest
RUN apt-get update 

# The following line will copy the syllabus.md file to the Docker container 
# using the path that is specified second.
COPY syllabus.md /syllabus.md
  1. Run docker build -t syllabus:first . from your lecture2/ directory, which should contain your Dockerfile and syllabus.md.
    - Note there is an "." at the end of the line. 
    - The `-t` flag tells the `build` command to tag your Docker image with a specific name. Check out this [link](https://www.freecodecamp.org/news/an-introduction-to-docker-tags-9b5395636c2a/) for an in-depth explanation of Docker tags.
    - If you choose to name the Dockerfile something else you could us: `docker build -t syllabus:first -f filename .`.  
  2. Run docker image ls. You should see your docker image at the top of the list. You should also see the ubuntu image we used to create our docker image in the list.

Run a docker container¶

Now we are ready to start up a Docker container using the image we built.

  1. Run docker run -it syllabus:first in your terminal window.
     - The combination of the flags `-it` will open an interactive shell in the Docker container.
     - You should see that your command-line prompt changes to `root@...`.
  2. You're now in the Docker container, which is running Linux. Use ls and ensure the syllabus.md file is in your container.
  3. In another terminal window (not the one connected to your Docker container), type docker ps.
    • You should see that you have one container that is running and that it was created a few minutes ago.



Let's count the lines that contain a numerical digit in syllabus.md. To do so run the command grep [0-9] syllabus.md.

Depending on your OS will give you different answers.

  • If you have a MacOS, you should see 52.
  • If you have Windows or Linux, then you should see 51.
  1. Now, run grep [0-9] syllabus.md | wc -l in the Docker container.

Exit and deleting

  1. Type exit in the Docker container window to leave the container.
  2. Type docker ps again (in any terminal window) and you should see that there are no containers running.
  3. If you would like to clean up your local Docker registry to remove images and stopped containers, follow these instructions.
In [ ]: