14 December, 2019

First stop on the Docker learning train - Docker for beginners

The first stop on my Docker learning train is from the Docker Samples with the tutorial Docker for beginners.

The tutorial has four chapters:
  • Setup
  • 1.0 Running your first container
  • 2.0 Webapps with Docker
  • 3.0 Deploying an app to a Swarm

Setup

The Setup chapter makes sure that Docker is installed and running on my machine. The tutorial points back to the Docker documentation for the installation steps. To verify that Docker is working run the following:
docker run hello-world

1.0 Running your first container

The key topics for this chapter include:
  • How to run a docker container.
  • How to list containers.
  • How to inspect a container.

Docker CLI commands

  • docker pull - pulls an image or repository from a registry
  • docker run - runs a container
    • This command can also pull a container
    • By default, the interactive shell will exit after running a script. Use the '-it' switch to keep the shell open.
      • Example: 
        docker run -it alpine /bin/sh
        
  • docker ps - list containers
    • By default, the command lists the running containers. 
    • To list all the containers use the switch '-a'
      • Example:
        docker ps -a
  • docker inspect - returns low-level information about a docker container

Terms

image - Docker images are the basis of containers. An Image is an ordered collection of root filesystem changes and the corresponding execution parameters for use within a container runtime. An image typically contains a union of layered filesystems stacked on top of each other. An image does not have state and it never changes. - Docker Glossary
container - A container is a runtime instance of a docker image.
A Docker container consists of
  • A Docker image
  • An execution environment
  • A standard set of instructions
The concept is borrowed from Shipping Containers, which define a standard to ship goods globally. Docker defines a standard to ship software. - Docker Glossary

2.0 Webapps with Docker

This chapter is broken into a few sections.

2.1 Run a static website in a container

Key topics for the section include:
  • How to run a container in detached mode.
  • How to publish the ports the container exposes.
  • How to name a container.
  • How to pass environment variables to the container.
  • How to stop a container.
  • How to remove a container.

2.2 Docker Images

Key topics for this section include:
  • What is a Docker image?
  • How to use 'tag' to pull a specific version of a container.

2.3 Create your first image

Key topics for this section include:
  • How to write a Dockerfile.
  • How to build the image.
  • How to run the image.
Notes about Dockerfiles

  • By convention, an instruction is written in UPPERCASE. This makes it easier to distinguish an instruction from an argument. 
  • Docker runs instructions in order.
  • A Dockerfile must begin with a 'FROM' instruction. 
  • Lines the begin with '#' are treated as a comment.
  • Guide: Best practices for writing Dockerfiles

Terms

base image - A base image has no parent image specified in its Dockerfile. It is created using a Dockerfile with the FROM scratch directive.
Child images are images that build on base images and add additional functionality. 
Official images are Docker sanctioned images. 
User images are images created and shared by users like you.
Dockerfile is a text document that contain all the commands a user could call on the command line to assemble an image. 

Docker CLI commands

  • docker run
    • -d - detached mode
    • -P - publish exposed container ports to random ports on the host
    • -e - pass environment variables to the container.
    • --name - allows a name to be specified for the container
  • docker stop - stops one or more containers
  • docker rm - removes one or more containers
    • -f - Force removal of a running container
  • docker port - List port mapping or a specific mapping for a container
  • docker images - list images
  • docker pull 
    • by default, pull gets the latest version
    • to get a specific version include the tag 
      • Example: 
        docker pull ubuntu:12.04
        
  • docker search - search the Docker Hub for images
  • docker build - build an image from a Dockerfile
    • -t - Name and optional a tag in the 'name:tag' format
  • docker login - Log into a Docker registry
  • docker push - Push an image or a repository to a registry

3.0 Deploy an app to a Swarm

Key topics for this chapter include:

  • How to create a swarm.
  • How to deploy. 

I was unable to make the example work properly on my machine. The docker swarm and docker stack executed without reporting any errors. The command 'docker ps' reports multiple active containers. I will need to come back to this tutorial at a later date to investigate further.

Terms

swarm - A swarm is a cluster of one or more Docker Engines running in swarm mode
Docker Swarm - Do not confuse Docker Swarm with the swarm mode features in Docker Engine.
Docker Swarm is the name of a standalone native clustering tool for Docker. Docker Swarm pools together several Docker hosts and exposes them as a single virtual Docker host. It serves the standard Docker API, so any tool that already works with Docker can now transparently scale up to multiple hosts.
Also known as : docker-swarm
swarm mode - Swarm mode refers to cluster management and orchestration features embedded in Docker Engine. When you initialize a new swarm (cluster) or join nodes to a swarm, the Docker Engine runs in swarm mode.

Docker CLI Commands







No comments:

Challenging myself to learn something new

I have recently set a big challenge for myself. I want to know about Machine Learning . To add to the challenge, I am trying out usin...