Thursday, September 24, 2020

How to Install and Use Docker

 Step 1: Install Docker in a linux vm or physical machine. Ubuntu will be used in this demo.

# sudo apt-get install

Step 2: Start and enable docker

# sudo systemctl start docker

# sudo systemctl enable docker

Step 3: Verify the version of docker

# sudo docker -v

Docker version 19.03.8, build afacb8b7f0

Step 4: Learn about subcommands on your own

# sudo docker

Usage:      docker [OPTIONS] COMMAND

 A self-sufficient runtime for containers


      --config string      Location of client config files (default


  -c, --context string     Name of the context to use to connect to the

                           daemon (overrides DOCKER_HOST env var and

                           default context set with "docker context use")

  -D, --debug              Enable debug mode

  -H, --host list          Daemon socket(s) to connect to

  -l, --log-level string   Set the logging level


                           (default "info")

      --tls                Use TLS; implied by --tlsverify

      --tlscacert string   Trust certs signed only by this CA (default


      --tlscert string     Path to TLS certificate file (default


      --tlskey string      Path to TLS key file (default


      --tlsverify          Use TLS and verify the remote

  -v, --version            Print version information and quit

 Management Commands:

  builder     Manage builds

  config      Manage Docker configs

  container   Manage containers

  context     Manage contexts

  engine      Manage the docker engine

  image       Manage images

  network     Manage networks

  node        Manage Swarm nodes

  plugin      Manage plugins

  secret      Manage Docker secrets

  service     Manage services

  stack       Manage Docker stacks

  swarm       Manage Swarm

  system      Manage Docker

  trust       Manage trust on Docker images

  volume      Manage volumes


  attach      Attach local standard input, output, and error streams to a running container

  build       Build an image from a Dockerfile

  commit      Create a new image from a container's changes

  cp          Copy files/folders between a container and the local filesystem

  create      Create a new container

  deploy      Deploy a new stack or update an existing stack

  diff        Inspect changes to files or directories on a container's filesystem

  events      Get real time events from the server

  exec        Run a command in a running container

Step 5: Test docker by running "hello world"

# sudo docker run hello-world

Hello from Docker!

This message shows that your installation appears to be working correctly.

 To generate this message, Docker took the following steps:

 1. The Docker client contacted the Docker daemon.

 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.


 3. The Docker daemon created a new container from that image which runs the

    executable that produces the output you are currently reading.

 4. The Docker daemon streamed that output to the Docker client, which sent it

    to your terminal.

 To try something more ambitious, you can run an Ubuntu container with:

 For more examples and ideas, visit:

Step 6: Download an image

# sudo docker pull postgres

Step 7: Verify the number of images that were pulled

# sudo docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

postgres            latest              0f10374e5170        2 weeks ago         314MB

hello-world         latest              bf756fb1ae65        4 months ago        13.3kB

Step 8: Start an access a container

# sudo docker run postgres

# sudo docker ps -a

# sudo docker run -it postgres bash

Other Commands to know:

# sudo docker stop container_id (graceful shutdown)

# sudo docker kill container_id (non graceful shutdown)

# sudo docker rm container_id (delete a stopped container)

# sudo docker build . (build your own container)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.