Key Word(s): Containers, Docker, Singularity



Installing Docker Desktop

  1. Install Docker Desktop. Use one of the links below to download the proper Docker application depending on your operating system. You will need to make an account on dockerhub.
    1. For Mac users, follow this link- https://docs.docker.com/docker-for-mac/install/.
    2. For Windows users, follow this link- https://docs.docker.com/docker-for-windows/install/
      1. You will need to install Hyper-V to get Docker to work.
    3. For Linux users, follow this link- https://docs.docker.com/install/linux/docker-ce/ubuntu/
  2. 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. If you have any issue, please do not worry since this lecture exercise can be completed by working in pairs.

The following exercise can be completed individually or in pairs.

Building a Dockerfile for a Linux container

  1. Create a lecture15/ directory in your course repo.
  2. Download the apollo13.txt file from HW1 to your lecture15/ directory.

    • Note: Use curl https://harvard-iacs.github.io/2019-CS207/homeworks/HW1/data/apollo13.txt -o apollo13.txt to download the apollo13.txt file from HW1.
    • Do not copy and paste into a file on your computer. This will give different character counts than if you download it.
  3. Open a new file called Dockerfile in a text editor. Save the file to your lecture15/ directory in your course repo.

  4. 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 apollo13.txt file to the Docker container 
     # using the path that is specified second.
     COPY apollo13.txt /apollo13.txt
  5. Run docker build -t lecture15:first . from your lecture15/ directory, which should contain your Dockerfile and apollo13.txt.
    1. The -t flag tells the build command to tag your Docker image with a specific name. Check out this link for an in-depth explanation of Docker tags.
  6. 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.
  7. Now we are ready to start up a Docker container using the image we built.
    1. Run docker run -it lecture15:first in your terminal window.
    2. The combination of the flags -it will open an interactive shell in the Docker container.
    3. You should see that your command-line prompt changes to root@....
  8. You're now in the Docker container, which is running Linux. Use ls and ensure the apollo13.txt file is in your container.
  9. In another terminal window (not the one connected to your Docker container), type docker ps.
    1. You should see that you have one container that is running and that it was created a few minutes ago.
  10. In HW1, we asked you to count the number of lines that contain a numerical digit in the apollo13.txt file. Depending on your OS, grep [0-9] apollo13.txt | wc -l will give you different answers. Run this command in your Docker container, and you should see 1404 printed to the screen.
  11. Now, run grep [0-9] apollo13.txt | wc -l in the additional terminal window in your lecture15/ directory.
    1. If you have a MacOS, you should see 1403.
    2. If you have Windows or Linux, then you should see 1404.
  12. Type exit in the Docker container window to leave the container.
  13. Type docker ps again (in any terminal window) and you should see that there are no containers running.
  14. If you would like to clean up your local Docker registry to remove images and stopped containers, follow these instructions.

Final deliverables

  1. Dockerfile