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¶
- Install
Docker Desktop
. Use one of the links below to download the proper Docker application depending on your operating system.- 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/ Note: 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/
- Once installed run the docker desktop.
- 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¶¶
- 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 thesyllabus.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.
- Open a new file called
Dockerfile
in a text editor. Save the file to yourlecture2/
directory. - 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
- Run
docker build -t syllabus:first .
from yourlecture2/
directory, which should contain yourDockerfile
andsyllabus.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 .`.
- 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.
Run a docker container¶¶
Now we are ready to start up a Docker container using the image we built.
- 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@...`.
- You're now in the Docker container, which is running Linux. Use
ls
and ensure thesyllabus.md
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.
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
.
- Now, run
grep [0-9] syllabus.md | wc -l
in the Docker container.
Exit and deleting¶
- 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.
In [ ]: