Friday, May 27, 2022

Docker 101 - Introduction


What is Container?



It is a technology which packages software into standardized units for development, shipment and deployment. Since it packages up code and all its dependencies, the application runs quickly and reliably from one computing environment to another. Reference


What is Docker?



Docker != Container

It is one of the container solutions, and there are many alternatives.

But Docker is container standards and industry leadership. Reference


Docker Installation



Recommended Approach: Follow this link

If it is the development environment only, then we can use this convenience script.


Post-Installation Steps



Add current User  to docker group



$ sudo groupadd docker
  $ sudo usermod -aG docker $USER


Verify Installation



Ex:
$ docker version
  $ docker info


Hello World from Docker Official Image




Ex:
$ docker container run hello-word

Result:
Unable to find image 'hello-world:latest' locally
  latest: Pulling from library/hello-world
  2db29710123e: Pull complete
  Digest: sha256:80f31da1ac7b312ba29d65080fddf797dd76acfb870e677f39...
  Status: Downloaded newer image for hello-world:latest

  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.
      (amd64)
  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:
  $ docker run -it ubuntu bash

  Share images, automate workflows, and more with a free Docker ID:
  https://hub.docker.com/

  For more examples and ideas, visit:
  https://docs.docker.com/get-started/

According to the explanation message from the hello-world output, we can use the following image to easily understand how Docker works. Reference





Basic Docker Commands


Get more info for docker command

Ex:
$ docker --help

Result:
...
  Management Commands:
  app*        Docker App (Docker Inc., v0.9.1-beta3)
  builder     Manage builds
  buildx*     Docker Buildx (Docker Inc., v0.8.2-docker)
  compose*    Docker Compose (Docker Inc., v2.5.0)
  config      Manage Docker configs
  container   Manage containers
  context     Manage contexts
  image       Manage images
  manifest    Manage Docker image manifests and manifest lists
  network     Manage networks
  node        Manage Swarm nodes
  plugin      Manage plugins
  scan*       Docker Scan (Docker Inc., v0.17.0)
  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
  ...

  Run 'docker COMMAND --help' for more information on a command.



Get more info for docker container command

Ex:
$ docker container --help

Result:
 Usage:  docker container COMMAND

   Manage containers

   Commands:
   attach      Attach local standard input, output, and error streams to a
running container
   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
   diff        Inspect changes to files or directories on a container's
filesystem
   exec        Run a command in a running container
   export      Export a container's filesystem as a tar archive
   inspect     Display detailed information on one or more containers
   kill        Kill one or more running containers
   logs        Fetch the logs of a container
   ls          List containers
   pause       Pause all processes within one or more containers
   port        List port mappings or a specific mapping for the container
   prune       Remove all stopped containers
   rename      Rename a container
   restart     Restart one or more containers
   rm          Remove one or more containers
   run         Run a command in a new container
   start       Start one or more stopped containers
   stats       Display a live stream of container(s) resource usage
statistics
   stop        Stop one or more running containers
   top         Display the running processes of a container
   unpause     Unpause all processes within one or more containers
   update      Update configuration of one or more containers
   wait        Block until one or more containers stop, then print their
exit codes

   Run 'docker container COMMAND --help' for more information on a command.


List all Containers

Ex:
$ docker container ls

Result:
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES


Get more info for docker container ls

Ex:
$ docker container ls --help

Result:
Usage:  docker container ls [OPTIONS]

  List containers

  Aliases:
  ls, ps, list

  Options:
  -a, --all             Show all containers (default shows just running)
  -f, --filter filter   Filter output based on conditions provided
      --format string   Pretty-print containers using a Go template
  -n, --last int        Show n last created containers
(includes all states) (default -1)
  -l, --latest          Show the latest created container (includes all
states)
      --no-trunc        Don't truncate output
  -q, --quiet           Only display container IDs
  -s, --size            Display total file sizes


Get all Containers including all status

Ex:
$ docker container ls -a

Result:
CONTAINER ID   IMAGE         COMMAND    CREATED          
d423b088f982   hello-world   "/hello"   45 minutes ago  

STATUS                     PORTS     NAMES
  Exited (0) 45 minutes ago             admiring_yonath


Remove a container

Ex:
$ docker container rm d42

Result:
d42


Get all images

Ex:
$ docker image ls

Result:
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
  hello-world   latest    feb5d9fea6a5   8 months ago   13.3kB


Show detail info on a image

Ex:
$ docker image history feb

Result:
IMAGE          CREATED        CREATED BY                                  
  feb5d9fea6a5   8 months ago   /bin/sh -c #(nop)  CMD ["/hello"]
  <missing>      8 months ago   /bin/sh -c #(nop) COPY file:505…  

SIZE      COMMENT
  0B
13.3kB


Remove an image

Ex:
$ docker image rm feb

Result:
Untagged: hello-world:latest
  Untagged: hello-world@sha256:80f31...
  Deleted: sha256:feb5d9fea6a5e9606a...
  Deleted: sha256:e07ee1baac5fae6a26...

No comments:

Post a Comment