Docker

 

Introduction to Docker

                                Docker is a platform that allows developers to automate the deployment of applications inside lightweight, portable containers. These containers include everything needed to run the application, such as the code, runtime, libraries, and system tools, ensuring that the application runs consistently across different environments.

Why Docker?

  1. Consistency: Docker ensures that your application will run the same regardless of where it is deployed, eliminating the "it works on my machine" problem.
  2. Efficiency: Containers are more lightweight and start faster than traditional virtual machines because they share the host system's kernel.
  3. Scalability: Docker makes it easy to scale applications horizontally, enabling quick replication of containers across multiple servers.

Getting Started with Docker

                                   To interact with Docker, you need to have it installed on your system. If you're not sure about SSH or how to set up your environment, refer to my previous blog. For now, let's focus on Docker.

Install Docker

Open your Linux terminal and run the following command to install Docker:

  comm : sudo apt install docker

Start Docker

Once Docker is installed, start the Docker service with:

comm : sudo systemctl start docker

-: You can also check the status of the Docker service to ensure it is running correctly:

comm : sudo systemctl status docker

Creating a Docker Container

Let's create a container using the Ubuntu image.

  1. Pull the Ubuntu Image

    Download the Ubuntu image from Docker Hub:

    comm : sudo docker pull ubuntu
     

    Creating a new container : 

    comm : sudo docker create  --name  container-name  image
     

  2. Note: If you encounter a timeout error, you may need to increase the HTTP timeout settings. Refer to additional resources or tools like GPT for guidance.

  3. Run a Container

    Create and start a container named mysql-container using the Ubuntu image

    comm : sudo docker run --name mysql-container -it ubuntu

    Breakdown of the command:

  4. --name specifies the name of the container.
  5. -it opens an interactive terminal.
  6. ubuntu is the image we downloaded.

Now you are inside your container's shell, ready to perform further configurations

Managing Docker Containers

Restarting and Accessing Containers

If you exit the container or restart your system, you can start and access your container again with:

comm : sudo docker start mysql-container
comm : sudo docker exec -it mysql-container bash

 

Checking Container Status

To check the status, uptime, or ID of your containers, use:

comm : sudo docker ps -a
 

Checking Ports

To see which ports are listening inside your container, first install the necessary tools:

comm : apt install net-tools

(Note: Do not use sudo inside the container as you already have elevated permissions.)

Stopping and Removing Containers

To stop and remove containers:

  1. Stop the Container:

    comm : sudo docker stop container_id_or_name 

    2. Remove the Container

    comm : sudo docker rm container_id_or_name

    3. To remove multiple containers at once:

comm : sudo docker rm container_id_or_name1 container_id_or_name2 ...

Conclusion

                          Docker simplifies the deployment and management of applications. Follow these steps to start using Docker and explore its vast potential. For a more visual guide, check out this

https://www.youtube.com/watch?v=htyxGoTt_f4 

 

Author: Haris
FAST '27, BS CS
Member, Research Lab COLAB-NU
Email: arainharis151@gmail.com

Feel free to reach out for questions or further assistance. Happy computing!

 



 

 

 



 

 

 

Comments

Popular posts from this blog

Progress Chef

Understanding HTTP/1.1, HTTP/2, and HTTP/3

Cryptography