Article
· Jun 5, 2023 8m read

Introduction to Docker

Hi Community,

In this article, we will learn the below topics listed below:

  1. What is Docker?
  2. Some of the Docker benefits
  3. How does Docker work?
  4. Docker Image
  5. Docker Container
  6. Docker Image repository
  7. InterSystems's Docker image repository
  8. Docker Installation
  9. Docker Basic Commands
  10. Running IRIS community edition by using docker
  11. Docker Desktop GUI

So Let's start.


1. What is Docker?

A beginner’s guide to Docker — how to create your first Docker application
Docker is Virtualization software that makes developing and deploying applications very easy. Docker does this by Packaging the application into a so-called container that retains everything the application needs to run, including the application's actual code, its libraries and dependencies, runtime, and environment configuration.

Docker is a containerization platform that allows developers to create, deploy, and run applications in containerized environment. Docker provides a way to package an application and its dependencies into a single container that can be run on any machine that supports Docker. That makes it easy to create portable, lightweight applications that can be deployed quickly and effortlessly.


2. Some of the Docker benefits

Below you can find some of the benefits of using the Docker:

  • Portability Docker containers can be run on any machine that supports Docker, making it easy to deploy applications across different environments.
  • Consistency By packaging an application and its dependencies into a container, Docker ensures that the application will run consistently, regardless of the underlying infrastructure.
  • Scalability Docker makes it painless to scale applications horizontally by running multiple instances of the same container.
  • Resource efficiency Docker containers are lightweight and require minimal resources, making them ideal for running on cloud infrastructure.
  • Security Docker provides a secure and isolated environment for running applications, reducing the risk of conflicts with other applications or the host system.

 

3. How does Docker work?

Docker creates a virtualized environment for an application called a container. A container is a lightweight, standalone and executable package that incorporates everything needed to run the application, including code, libraries, and dependencies. Containers are isolated from the host system. Therefore, they can run on any machine that supports Docker, regardless of the underlying operating system or hardware.

Containers are created from images which are read-only templates that define the application and its dependencies. Those images are stored in a central repository, called a registry, such as Docker Hub or a private registry. Developers can create custom images themselves or use pre-built ones from the registry.

When a container is launched, it gets built from an image and given its own isolated file system, network, and process space. The container can then run the application as if it were running on a dedicated server.

 

4. Docker Images

A Docker image is a lightweight, standalone, and executable package that retains everything required to execute an application, including the code, libraries, and dependencies. Docker images are employed to build and run containers, which are isolated environments that can be used to run applications.

Docker images are built from a Dockerfile, which is a text file that contains a set of instructions for building the image. The Dockerfile specifies the base image, the application code and dependencies, the environment variables, and other configuration options necessary for creating the image.

Docker images are stored in a registry, such as Docker Hub or a private one. Every time when a container is created from an image, it runs as a separate process on the host machine, isolated from other processes and containers.

Docker images can be used to deploy applications in a consistent way across different platforms. They make it easy to package, distribute, and deploy applications, and ensure that they run the same way everywhere.

 

5. Docker Containers

A running instance of an image is a Container, which, as mentioned above, is a lightweight, standalone, and executable package that includes everything needed to run an application, including the code, libraries, and dependencies.

A Docker container provides an isolated environment for running an application, ensuring that it has all the resources it needs to run correctly. Each container runs as a separate process on the host machine and has its own file system, network, and other resources.

Docker containers are designed to be portable and easy to deploy. They can be run on any machine that has Docker installed, regardless of the underlying operating system or hardware. Containers provide a consistent environment for running applications, making it more comfortable to move applications between different environments, such as development, testing, and production.

Docker containers can be managed with the help of the Docker CLI or such Docker tools as Docker Compose or Kubernetes. They can be started, stopped, paused, and restarted as needed. They can also be monitored and managed using a range of tools and platforms.

Overall, Docker containers provide a flexible and scalable way to package and deploy applications, making it less complicated to manage and scale complex applications across different environments and platforms.

 

6. Docker Images Repository

Docker hosts one of the biggest Docker Repositories, called Docker Hub. It is a storage and distribution system for Docker images. It provides a central repository for developers and organizations to share and distribute their Docker images, making it more enjoyable to build, share, and deploy applications with Docker.

Docker Hub allows users and organizations to store and manage their Docker images and also provides such features as versioning, tagging, and collaboration. Users can search for and download images from Docker Hub, as well as publish their own images to the registry.

In addition to the public registry, Docker Hub provides a private registry for organizations that want to manage their own Docker images and ensure that they are only accessible to authorized users.

 

 

7. InterSystems Docker image repository

By using the Docker Hub search feature, we can find InterSystems images on Docker hub.

 

8. Installation of Docker

In order to use Docker, we need to install it on our system. Docker provides installation packages for various operating systems, including Windows, macOS, and Linux.
Navigate to Docker website.  We can download the installation package from the Docker website, run the installer, and follow the prompts to complete the installation.

After installing Docker Desktop, we can use the Docker CLI (Command Line Interface) to manage Docker images, containers, networks, and other resources.  

 

9. Docker Basic Commands

Here we will review some of the docker CLI basic commands. (Make sure to run Docker Desktop before using the commands detailed below)

9.1 List images (locally)
We can use the docker image ls command to list all the Docker images that are available on our system. Here's how you can use this command:

docker image ls


As you can see, currently, we do not have any images locally


9.2 Pull images from the Docker repository

We can use the docker pull command to download a Docker image from a registry

docker pull <image>

Let us pull intersystemsdc/iris-community image from the docker hub

At this point, we should use the list command to view images locally

Well done! The iris-community image was pulled successfully


9.3 Remove image locally
We can use the docker image rm  command to delete the image from our system

docker image rm <image name>

 

9.4 List all existing containers (running and not running)
We can employ the docker ps command to list down running containers

docker ps 


As shown in the picture, no container is running at this time.

9.5 Create and start the container
We can use the docker run command to create and start the container

docker run <image id/namge>

Let's create and start the container from iris-community image

Here -d or --detach means the following: Run the command in the background and return control to the terminal.

It is time to list down running containers once more

docker ps

We can see that our iris-community image container is running now.

9.6 Stop the specific container
We can use the docker stop command to stop the running container

docker stop <container id/name>

 

9.7 Start the specific container
We can use the docker start command to start a previously stopped container in Docker. 

docker start <container id/name>

9.8 Restart the specific container

We can use the docker restart command to stop and start the running container in the Docker

docker restart <container id/name>

9.9 Remove the specific container

We can use the docker rm command to remove the stopped container

docker rm <container id/name>

 

9.10 Running a command inside a running container
We can employ the docker exec command to run a command inside a running container. It can come in handy when performing administrative tasks or for debugging purposes.

docker exec -it my-container sh

Some common options for the docker exec command are:

  • -i or --interactive:  this command keeps STDIN open even if not attached, allowing you to interact with the container.
  • -t or --tty:  this command allocates a pseudo-TTY to the command, allowing you to use terminal commands inside the container.
  • -d or --detach:  this runs the command in the background and returns control to the terminal.

 

10. Running IRIS community edition by using docker

Utilize the command listed below to run the container by employing the iris-community image

docker run -d -p 52773:52773 intersystemsdc/iris-community

Some common options for the docker exec command are the following:

  • -d : this command is used to start a new Docker container in detached mode, it means that the container will run in the background, and we can continue to use the terminal for other tasks.
  • -p:  this command helps us publish a container's port to the host machine to make it possible to access the container from outside the Docker network.

In the illustration below you can spot IRIS running in the Docker.

 

11. Docker Desktop GUI

Docker desktop also has GUI where we can utilize all the above-mentioned commands graphically.

 

Summary

Docker is a powerful tool that allows developers and IT teams to create, deploy, and run applications in a containerized environment. By providing portability, consistency, scalability, resource efficiency, and security, Docker makes it easy to deploy applications across different environments and infrastructures. With the growing popularity of containerization, Docker is becoming an essential tool for modern software development and deployment.
In the upcoming article, we will learn how to use Docker file (employed to build a Docker image), Docker compose (a YAML file that specifies the configuration options for each container in the application), and Docker volume (a persistent data storage mechanism operated to share data between Docker containers and the host machine.)

 


Thank you for reading!

Discussion (10)5
Log in or sign up to continue

This is great!

I would love to see an article about Dockeriz-ing legacy applications including how to manifest your system's current security configurations and other important configs like OAuth servers, productions, and SSL configs.  

Most articles and example seemed geared to "here's a fresh copy of IRIS for you to do your thing!"  I have sat with the Docker template in the InterSystems community Git repo many times only to find myself with a half working version of my current application.  I also am not that good with Docker in the first place so I admit I have short comings and much to learn still.  

Great article, @Muhammad Waseem !

I'd add a docker command to start terminal.

First this one launches IRIS and creates a fresh namespace alone with the user 'demo' and password 'demo':

docker run --rm --name iris-demo -d -p 9091:1972 -p 9092:52773 -e IRIS_PASSWORD=demo -e IRIS_USERNAME=demo -e IRIS_NAMESPACE=DEV intersystemsdc/iris-community

Then to launch a terminal in PROD namespace:

docker exec -it iris-demo iris session iris -U DEV

DEV>