Docker guide

Core Components of Docker

Docker Engine is a client-server based application. It is responsible for the overall functioning of the Docker platform. It consists of 3 main components.

  1. Server: runs a daemon known as dockerd (a process). It is responsible for creating and managing Docker Images, Containers, Networks and Volumes on the Docker platform.
  2. REST API: specifies how the applications can interact with the Server
  3. Client: a command line interface

Docker Terminology

Let us take a quick look at some of the terminology associated with Docker.

  • Docker Image: a template that contains the application, and all the dependencies required to run that application on Docker
  • Docker Container: a running instance of the Docker Image
  • Docker Hub: official online repository where you could find all the Docker Images that are available for us to use

Docker Commands

  • Create a new container
    docker create [options] IMAGE [commands] [arguments]

    1
    2
    docker create fedora
    docker create -t -i ubuntu bash #add terminal and execute bash
  • View containers

    1
    2
    docker ps       #containers running
    docker ps -a #all containers created
    • ContainerId: unique string consisting of alpha-numeric characters, associated with each container
    • Image: name of the Docker Image used to create this container
    • Command: any application specific commands that needs to be executed when the container is started
    • Created: the time elapsed since this container has been created
    • Status: the current status of the container, along with the time elapsed, in its present state
    • Ports: displays any port mappings defined for the container
    • Names: unique name apart of the containerId
  • Start any stopped container
    docker start [options] CONTAINER ID/NAME [CONTAINER ID/NAME…]

    1
    2
    docker start 30986
    docker start weblogic
  • Stop any running container
    docker stop [options] CONTAINER ID/NAME [CONTAINER ID/NAME…]

    1
    2
    docker stop 30986
    docker stop weblogic
  • Restart any running container
    docker restart [options] CONTAINER ID/NAME [CONTAINER ID/NAME…]

    1
    2
    docker restart 30986
    docker restart weblogic
  • Combination of the docker create and the docker start command
    docker run [options] IMAGE [commands] [arguments]

    1
    2
    docker run ubuntu
    docker run -it ubuntu #interact with the container
  • Delete a container
    docker rm [options] CONTAINER ID/NAME [CONTAINER ID/NAME...]

    1
    docker rm weblogic
  • Lists out all the Docker Images that are present on the Docker Host

    1
    docker images
    • Repository: This represents the unique name of the Docker Image
    • Tag: each image is associated with a unique tag. A tag basically represents a version of the image
    • ImageId: unique string consisting of alpha-numeric characters, associated with each image
    • Created: the time elapsed since this image has been created
    • Size: the size of the image
  • Remove an image from the Docker Host
    docker rmi [options] IMAGE NAME/ID [IMAGE NAME/ID...]

    1
    docker rmi mysql