Docker Basics you need to know...

Docker Basics you need to know...

What is Docker?

docker-cloud-twitter-card.png

An open-source platform founded by Solomon Hykes in 2013. A stage for developers and sysadmins to build, run, and share applications with Containers. The utilization of containers to deploy applications is called containerization. It allows us to build images for your applications which we can share with anyone working on any operating system.

"Simplifies and accelerates the workflow, while giving developers the freedom to innovate with their choice of tools, application stacks, and deployment environments for each project."

What is Containerization?

A Container is a standard unit of software that bundles up code and every one of its conditions so the application runs rapidly and dependably starting with one registering climate then onto the next. A Docker Container image is a lightweight, independent, executable bundle of software that incorporates all that expected to run an application:

  • code
  • runtime
  • system tools
  • framework libraries
  • settings.

Hands on Docker

Installing Docker on Ubuntu

The Docker installation package available in the official Ubuntu repository may not be the latest version. To ensure we get the latest version, we’ll install Docker from the official Docker repository. To do that, we’ll add a new package source, add the GPG key from Docker to ensure the downloads are valid, and then install the package.

First, update your existing list of packages:

sudo apt update

Next, install a few prerequisite packages which let apt use packages over HTTPS:

sudo apt install apt-transport-https ca-certificates curl software-properties-common

Then add the GPG key for the official Docker repository to your system:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Add the Docker repository to APT sources:

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"

Next, update the package database with the Docker packages from the newly added repo:

sudo apt update

Make sure you are about to install from the Docker repo instead of the default Ubuntu repo:

apt-cache policy docker-ce

You’ll see output like this, although the version number for Docker may be different:

Screenshot (536).png

Finally, install Docker:

sudo apt install docker-ce

Screenshot (538).png Docker should now be installed, the daemon started, and the process enabled to start on boot. Check that it’s running:

sudo systemctl status docker

The output should be similar to the following, showing that the service is active and running:

Screenshot (539).png

SUCCESSFULLY INSTALLED DOCKER IN YOUR SYSTEM !!!

Working with Docker Images

Docker containers are built from Docker images. By default, Docker pulls these images from Docker Hub, a Docker registry managed by Docker, the company behind the Docker project. Anyone can host their Docker images on Docker Hub, so most applications and Linux distributions you’ll need will have images hosted there.

To check whether you can access and download images from Docker Hub, type:

docker run hello-world

The output will indicate that Docker in working correctly:

Screenshot (540).png Docker was initially unable to find the hello-world image locally, so it downloaded the image from Docker Hub, which is the default repository

To find an image for Redis, you would use

docker search redis

Screenshot (543).png

Docker will run a command in the foreground.

To run in the background, the option -d needs to be specified.

docker run -d redis

Screenshot (548).png

If we directly use the this command it will automatically use the pull command and will pull the image as shown in the output.

docker pull redis

The launched container is running in the background

docker ps

Screenshot (544).png command lists all running containers, the image used to start the container and uptime.

The command docker inspect

docker inspect <friendly-name|container-id>

Screenshot (545).png provides more details about a running container, such as IP address.

The command docker logs

 docker logs <friendly-name|container-id>

Screenshot (549).png will display messages the container has written to standard error or standard out.

To see the images that have been downloaded to your computer, type:

docker images

The output will look similar to the following:

Screenshot (553).png

There are commands for starting and stopping the specified container.

The docker start command starts the container and returns the container ID as output.

docker start "container_id''

The docker stop command will stop the container and returns the container ID as output.

docker stop "container_id"

Screenshot (551).png

Conclusion

In this tutorial you learnt Docker, Containers, installed Docker, worked with images.

Stay Connected for more.