Key Word(s): Containers, Docker, Singularity
Installing Docker Desktop¶
- 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 ondockerhub
.- For Mac users, follow this link- https://docs.docker.com/docker-for-mac/install/.
- For Windows users, follow this link- https://docs.docker.com/docker-for-windows/install/
- You will need to install Hyper-V to get Docker to work.
- For Linux users, follow this link- https://docs.docker.com/install/linux/docker-ce/ubuntu/
- 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¶
- Create a
lecture15/
directory in your course repo. Download the
apollo13.txt
file from HW1 to yourlecture15/
directory.- Note: Use
curl https://harvard-iacs.github.io/2019-CS207/homeworks/HW1/data/apollo13.txt -o apollo13.txt
to download theapollo13.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.
- Note: Use
Open a new file called
Dockerfile
in a text editor. Save the file to yourlecture15/
directory in your course repo.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
- Run
docker build -t lecture15:first .
from yourlecture15/
directory, which should contain yourDockerfile
andapollo13.txt
.- The
-t
flag tells thebuild
command to tag your Docker image with a specific name. Check out this link for an in-depth explanation of Docker tags.
- The
- Run
docker image ls
. You should see your docker image at the top of the list. You should also see theubuntu
image we used to create our docker image in the list. - Now we are ready to start up a Docker container using the image we built.
- Run
docker run -it lecture15: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@...
.
- Run
- You're now in the Docker container, which is running Linux. Use
ls
and ensure theapollo13.txt
file is in your container. - 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.
- 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 see1404
printed to the screen. - Now, run
grep [0-9] apollo13.txt | wc -l
in the additional terminal window in yourlecture15/
directory.- If you have a MacOS, you should see
1403
. - If you have Windows or Linux, then you should see
1404
.
- If you have a MacOS, you should see
- Type
exit
in the Docker container window to leave the container. - Type
docker ps
again (in any terminal window) and you should see that there are no containers running. - If you would like to clean up your local Docker registry to remove images and stopped containers, follow these instructions.
Final deliverables¶
- Dockerfile