Title: 544
Tags: lec4

Q: If you want to download an image X from DockerHub to your VM, what command do you use?
A: docker pull X

Q: How can you see all the Docker images on your VM?
A: docker images

Q: How can you give a Docker image "a" an additional second name, "b"?
A: docker tag a b

Q: How can you launch a container from image X?
A: docker run X

Q: How can you see existing containers, including those exited?
A: For running containers:
docker ps
For exited ones too, add "-a":
docker ps -a

Q: How can you delete a container X?
A: docker rm X

Q: How can you delete an image X?
A: docker rmi X

Q: How can you see Docker's disk utilization?
A: docker system df

Q: How can you cleanup unnecessary Docker data to free up space?
A: docker system prune

Q: How can you see the output (for example prints) for an application running inside container X?
A: docker logs X

Q: How do you run a command (lets say "ls") inside a running container X?
A: docker exec X ls

Q: How do you see resource consumption of running containers?
A: docker stats

Q: How do you get a bash shell inside an existing container X?
A: docker exec -it X bash

Q: How do you cause a container X to immediately quit?
A: docker kill X
This sends a kill signal, which the container cannot ignore.

Q: How do you use the Dockerfile in the current directory to build an image X?
A: docker build . -t X

Q: What is the difference between "docker rm" and "docker kill"
A: After "docker kill", the container won't be running, but it will still exist (you can see it with "docker ps -a").  "docker rm" actually cleans up the space that was used by that container.

Q: In a Dockerfile, how do you specify a base image X?
A: FROM X

Q: In a Dockerfile, how do you execute a command, say "apt update"?
A: RUN apt update

Q: In a Dockerfile, how do you copy a file X.txt (in the same directory on the VM) to /Y.txt (in the image)?
A: COPY X.txt /Y.txt

Q: In a Dockerfile, why is a single install line preferred?
RUN apt-get update && apt-get install -y ...
In contrast to two lines:
RUN apt-get update
RUN apt-get install -y ...
A: The "update" refreshes the VM's knowledge of what packages are in the apt repositories, and "install" actuall installs something from a repository.  If you wait too long between an update and install, apt's view of the repositories will be stale, and the install won't work.
Docker builds cache results on a line-by-line basis to avoid running repeat commands.  That means that it might not run "apt-get update" again if it has been run previously.  Usually that's ok, but in this case we want it to be recent.

Q: How do you cause a container X to quit gracefully?
A: docker stop X
This sends a terminate signal to the container, which the application can catch and then handle by cleaning up before stopping.  If it takes too long, a kill signal will be sent, though.