Docker and Kubernetes

What is Docker?

  • Docker is a platform that allows one to develop and deploy applications in a isolated manner along with all of their dependencies.

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 Commands

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

Docker Container Commands

Start 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.
docker run name-of-container
Gracefully Stop Container:
– If we have provided a container with a friendly name we can use that instead of the hash.
docker container stop <hash>
Force Container Shutdown:docker container kill <hash>
List All Containers:docker container ls --all
Show Only Running Containers:docker container ls
Give Container Friendly Name:docker build -t name
Run Container Interactively:docker run --interactive --tty name-of-container bash
Run Container Detached:
– Example: docker run --detach --publish 80:80 --name nginx
– One can use -P to map all ports.
docker run --detach --publish <port>:<port> --name <name-of-container> <name-of-image>
Attach to Running Container:
– To exit container without stopping press: Ctrl+P Ctrl+Q
docker container attach <nameofcontainer>
Remove specified container from local machine:
– Use -f or --force to force the removal.
docker container rm <hash>
Inspect Container:docker container inspect <name>
View Container Logs:
– 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.
docker container logs <nameofcontainer>
View Container Diff:
– Shows a list of files added/modified/deleted since the base layer.
docker container diff <nameofcontainer>

Docker Image Commands

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 Machine Commands

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

Other Useful Docker Commands

Get the IP address assigned to a container:docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' name-of-container

Dockerfile

Docker Compose

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

Tooling

Terminology

Some Other Stuff…

Bibliography