Docker and Kubernetes

What is Docker?

Why Use Docker?

For a more extensive discussion of Docker’s advantages see Schenker’s Learn Docker – Fundamentals of Docker 18.x, specifically Chapter 1.

  • Automation – Using containers significantly increases the amount of automation that can occur.
  • Cost Savings – By using a thin layer as opposed to the thicker Virtual Machine model it allows more processes to be run on less hardware.
  • Developer Productivity – Allows for the creation of reusable and shareable development environments.
  • Deployability – It is easier and quicker to deploy applications to production when containerized.
  • Security – Use isolation built into Docker containers to keep applications from affecting one another.
  • Scalability – Using Kubernetes one can scale one’s applications massively.

Docker Commands

The Docker CLI can be used in a number of different ways, some of the more common commands are listed below. In general, a Docker command follows this form:

  • begins with docker (the name of the CLI we are using),
  • a context (like containers),
  • a command (like run), and
  • can include specific processes to run in the container.
  • The end result: docker thecontext thecommand theprocess

Docker General

  • Check Docker Version: docker --version
  • Details About Installed Version: docker info
  • View Docker CLI Help: docker --help
    • Can also be run in a specific context/on a command like: docker container ls -h
  • Login to Docker Public Registry: docker login

Docker Container

  • Start: docker run name-of-container
    • If we do not have a local copy of the image it will be pulled from the Docker repository.
    • Use --d to specify that this is a Linux daemon. Use --name to provide a friendly name for the container.
  • Gracefully Stop: docker container stop <hash>
    • If we have provided a container with a friendly name we can use that instead of the hash.
  • Force Shutdown: docker container kill <hash>
  • List: docker container ls --all
    • Show Only Running: docker container ls
  • Give Friendly Name: docker build -t name
  • Run Interactively: docker run --interactive --tty name-of-container bash
  • Run Detached: docker run --detach --publish <port>:<port> --name <name-of-container> <name-of-image>
    • Example: docker run --detach --publish 80:80 --name nginx
    • One can use -P to map all ports.
  • Attach to Running Container: docker container attach <nameofcontainer>
    • To exit container without stopping press: Ctrl+P Ctrl+Q
  • Remove specified container from local machine: docker container rm <hash>
    • Use -f or --force to force the removal.
  • Inspect Container: docker container inspect <name>
  • View Container Logs: docker container logs <nameofcontainer>
    • Use --tail or -t before nameofcontainer to get only the tail of the logs (include number of lines to return)
    • Use --tail with --flow in above manner to continue getting newer log entries.
  • View Container Diff: docker container diff <nameofcontainer>
    • Shows a list of files added/modified/deleted since the base layer.

Docker Images

  • List Downloaded: docker image ls
  • Associate Image with username/repo and tag: docker tag image username/repository:tag
  • Publish to the Repository: docker push username/repository:tag
  • Remove specified image from local machine: docker image rm <image id>
  • Persist Changes to a Container Into a New Image: docker container commit <name-of-container> <name-of-image>
  • View Changes Made to Build Image: docker image history <name-of-container>

Docker Virtual Machines

  • List Virtual Machines: docker-machine ls
  • Connect to Docker Virtual Machine: docker-machine ssh nameofvm

Minikube Commands

  • Start: minikube start
    • If running on Windows you may need to specify if you are using Hyper-V:
      minikube start --vm-driver=hyper --hyperv-virtual-switch="Name of Switch"

Kubernetes Commands


Docker Compose



Some Other Stuff…

  • Start with Install Docker for Windows.
  • Then Get Started with Docker for Windows.
  • Docker for Windows runs in the taskbar notifications area.
    • You’ll want to check “Expose daemon on tcp://localhost:2375 without TLS” if using PhpStorm.
    • Allows one to configure auto startup, sharing local drives with containers (only needed for Linux containers), set resources used by Docker, configure network, proxies, configure registries (where images are hosted), Kubernetes, reset configuration, and etc.


  • This page is based primarily on Docker Documentation and Gabriel N. Schenker’s Learn Docker 18.x.