What is a Container? A container is simply a running image that allows you to utilize the application. Containerization is OS-based virtualization. A container is simply a running image that allows you to utilize the application.
What is Docker? Docker is the world’s leading software container platform. It is written in the Go language. It benefits both developers and system administrators making it a part of many DevOps toolchains. Docker is designed in an efficient way to make it easier to create, deploy, run applications by using containers. Docker is used to package an application and its dependencies together so that it can work in any environment like testing, development, or production.
Its architecture : Docker architecture consists of Docker client, Docker Daemon running on Docker Host, and Docker Hub repository. Docker has client-server architecture in which the client communicates with the Docker Daemon running on the Docker Host using a combination of REST APIs, Socket IO, and TCP. If we have to build the Docker image, then we use the client to execute the build command to Docker Daemon then Docker Daemon builds an image based on given inputs and saves it into the Docker registry. If you don’t want to create an image then just execute the pull command from the client and then Docker Daemon will pull the image from the Docker Hub and finally if we want to run the image then execute the run command from the client which will create the container.
I hope you had a brief idea about what Docker is. Now, let's enlighten you in some commands of it.
- Starting Docker This command in docker starts the docker container with the container id mentioned in the command.
vibflare@vibflare:/home/vibflare$ docker start 09ca6feb6efc 09ca6feb6efc
- Kill Stop the docker container immediately. Docker stop command stops the container gracefully, that’s the difference between a kill and stop commands.
vibflare@vibflare:/home/vibflare$ docker kill 09ca6feb6efc 09ca6feb6efc
3.Commit Save a new docker image with container id mentioned in the command on the local system. In the example below, vibflare is the username, and httpd_image is the image name.
vibflare@vibflare:/home/vibflare$ docker commit 09ca6feb6efc vibflare/httpd_image sha256:d1933506f4c1686ab1a1ec601b1a03a17b41decbc21d8acd893db090a09bb31c
4.Login Login into docker hub. You will be asked your docker hub credentials to log in.
vibflare@vibflare:/home/vibflare$ docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to hub.docker.com to create one.
Username: vibflare
Password:
Configure a credential helper to remove this warning. See
docs.docker.com/engine/reference/commandlin..
Login Succeeded
5.Push Upload a docker image with the image name mentioned in the command on the docker hub.
vibflare@vibflare:/home/geekflare$ docker push geekflare/httpd_image
The push refers to a repository [docker.io/geekflare/httpd_image]
734d9104a6a2: Pushed
635721fc6973: Mounted from library/httpd
bea448567d6c: Mounted from library/httpd
bfaa5f9c3b51: Mounted from library/httpd
9d542ac296cc: Mounted from library/httpd
d8a33133e477: Mounted from library/httpd
latest: digest: sha256:3904662761df9d76ef04ddfa5cfab764b85e3eedaf10071cfbe2bf77254679ac size: 1574
- Docker network The following command in docker lists the details of all the networks in the cluster.
vibflare@vibflare:/home/vibflare$ docker network ls
NETWORK ID NAME DRIVER SCOPE
85083e766f04 bridge bridge local
f51d1f3379e0 host host local
5e5d9a192c00 none null local There are several other docker network commands.
Usage: docker network COMMAND
Manage networks
Commands:
connect Connect a container to a network
create Create a network
disconnect Disconnect a container from a network
inspect Display detailed information on one or more networks
ls List networks
prune Remove all unused networks
rm Remove one or more networks
Run 'docker network COMMAND --help' for more information on a command.
- Docker info Get detailed information about docker installed on the system including the kernel version, number of containers and images, etc.
vibflare@vibflare:/home/vibflare$ docker info
Containers: 3
Running: 1
Paused: 0
Stopped: 2
Server Version: 18.09.6
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: bb71b10fd8f58240ca47fbb579b9d1028eea7c84
runc version: 2b18fe1d885ee5083ef9f0838fee39b62d653e30
init version: fec3683
Security Options:
apparmor
seccomp
Profile: default
Kernel Version: 4.18.0-25-generic
Operating System: Ubuntu 18.10
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 4.982GiB
Name: vibflare
ID: RBCP:YGAP:QG6H:B6XH:JCT2:DTI5:AYJA:M44Z:ETRP:6TO6:OPAY:KLNJ
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Username: geekflare
Registry: index.docker.io/v1
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
- Checking history Copy a file from a docker container to the local system.
vibflare@vibflare:/home/vibflare$ sudo docker cp 09ca6feb6efc:/usr/local/apache2/logs/httpd.pid /home/vibflare/ [sudo] password forvibflare:
Run the command below to check if the file got copied or not.
vibflare@vibflare:/home/vibflare$ ls
Desktop Documents example examples.desktop httpd.pid nginx_new.yml nginx.yml
- Checking history Shows the history of a docker image with the image name mentioned in the command.
vibflare@vibflare:/home/vibflare$ docker history httpd
IMAGE CREATED CREATED BY SIZE COMMENT
ee39f68eb241 2 days ago /bin/sh -c #(nop) CMD ["httpd-foreground"] 0B
2 days ago /bin/sh -c #(nop) EXPOSE 80 0B
2 days ago /bin/sh -c #(nop) COPY file:c432ff61c4993ecd… 138B
4 days ago /bin/sh -c set -eux; savedAptMark="$(apt-m… 49.1MB
4 days ago /bin/sh -c #(nop) ENV HTTPD_PATCHES= 0B
4 days ago /bin/sh -c #(nop) ENV HTTPD_SHA256=b4ca9d05… 0B
4 days ago /bin/sh -c #(nop) ENV HTTPD_VERSION=2.4.39 0B
4 days ago /bin/sh -c set -eux; apt-get update; apt-g… 35.4MB
4 days ago /bin/sh -c #(nop) WORKDIR /usr/local/apache2 0B
4 days ago /bin/sh -c mkdir -p "$HTTPD_PREFIX" && chow… 0B
4 days ago /bin/sh -c #(nop) ENV PATH=/usr/local/apach… 0B
4 days ago /bin/sh -c #(nop) ENV HTTPD_PREFIX=/usr/loc… 0B
5 days ago /bin/sh -c #(nop) CMD ["bash"] 0B
5 days ago /bin/sh -c #(nop) ADD file:71ac2625. I hope it had been helfpul.