Level 0 Docker Cheat Sheet

Level 0 Docker Cheat Sheet

I’ve been playing around and modifying some existing Docker containers recently and here’s a couple of commands that I found out I use a lot. There’s a lot of extra flags you can give these little commands and you can peruse the docs for more information on them.

docker ps lets you list all your running containers and their details. A lot of the times you need the container name or ID for various reasons and this allows you to grab that information. Super handy.

Another good command for listing things (images specifically) is docker image ls. This lets you list all of the images.

docker logs [container name] is great for debugging and checking any logs that may occur in your container.

docker exec -it [container name or ID] /bin/bash lets you start a bash session in the container you define. You can use the container name or it’s id (which you handily got from using docker ps. The -it is saying to keep STDIN open even if not attached and to allocate a pseudo-TTY. Within this you can go to town making changes. Keep in mind the container is stateless, so you’re not going to have anything saved if you restart the container. Use exit to quit and return to your main terminal.

docker kill [container name or ID] will kill the container and you’ll no longer see it in your list-o-docker-containers when you run docker ps. However to completely remove it, you may need to follow it up with docker rm [container name or ID] if you get an error fussing about already being in use by container X. I’ve found this to be the case for me a lot.

-Rachel

Rachel Learns About Docker: Basic Definitions

Rachel Learns About Docker: Basic Definitions

So Docker. Docker. Everyone’s talking about Docker a lot. Everyone says Docker is important. So what does one do about all this Docker? Well, I started reading the documentation because I have only a vague idea of what it is supposed to do.

I do like their logo.

My initial thoughts on reading the overview:

  • Seems very similar to Python virtual environments but not restricted to just Python.
  • I have a suspicion that I could develop and deploy my apps for work easier with this.
  • There’s a lot to learn and a lot of definitions to keep straight and remember.

For my own benefit, I’m going to outline here some key definitions from my reading. Usually writing something down helps me remember it and solidify the concepts.

Docker consists basically of images that you use to make containers which allows you to have a lot more flexibility with moving around and editing and deploying applications. Below are some basic definitions are each, which I found helpful to have outlined a bit more succinctly than their wordier explanations in the official documentation.

Docker Images

  • Read only template
  • Generally base it on one image and then customize your own image to suit your needs
  • Defined in a Dockerfile
  • Like onions and ogres, Dockerfiles have layers. Unlike ogres, Dockerfiles define the layers with instructions.
  • Only changed layers are rebuilt when the image is rebuilt
  • The image provides the filesystem

Docker Containers

  • TL;DR a container is an encapsulated running process with it’s own filesystem
  • A runnable image instance
  • Define your container with its image and your configuration options
  • Isolated from everything else and you get to control networking, storage, etc on it.
  • Uses namespaces for each container and container isolation
  • Use control groups to limit an application’s resources

Docker Services

  • Swarm = scale containers across multiple Docker daemons
  • Daemons communicate through the Docker API
  • Lets you define the state for your swarm.

Well, there’s the very basic gist from my reading. I was able to get Docker desktop successfully installed and running no problems with their documentation. More later.

-Rachel