Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Docker»Discover the Power of Docker: Installing and Using Docker on Ubuntu and Debian!

    Discover the Power of Docker: Installing and Using Docker on Ubuntu and Debian!

    By RahulDecember 14, 20226 Mins Read

    Docker is an open-source platform that enables developers to create, deploy, and manage applications in a lightweight, secure, and efficient manner. It uses containers, which are lightweight and portable, to package applications and related dependencies into isolated environments. Docker containers can be deployed on any operating system and can be used to run applications in any language or framework.

    Advertisement

    Docker is based on the idea of containerization, which is the process of packaging applications and their dependencies in isolated environments. This helps developers quickly and easily deploy applications without having to worry about managing dependencies and configuring system settings.

    Docker containers are also highly portable and can be easily transferred from one system to another. This makes it possible to develop applications on one machine, deploy them on another, and move them between different hosting environments with minimal effort.

    Advantages of Using Docker

    Docker has several advantages over traditional application deployment methods.

    • First, Docker makes it easy to package and deploy applications in a consistent manner. This ensures that applications are always running the same version of the code and have the same configuration across all environments.
    • Second, Docker containers are lightweight, making them fast and easy to deploy. This makes it possible to quickly scale up or down as needed, reducing the cost of hosting applications.
    • Third, Docker containers are secure. Each container is isolated from other containers, making it difficult for malicious code to spread across systems. This also makes it easier to apply security patches, as only the containers affected by the patch need to be updated.
    • Finally, Docker makes it easy to manage applications at scale. With the help of orchestration tools such as Kubernetes, developers can easily manage the lifecycle of multiple containers and ensure that applications are running smoothly.

    Installing Docker on Ubuntu & Debian

    Installing Docker on Ubuntu is a straightforward process. Simply follow the below steps:

    1. First of all, remove the default version of Docker from your system:
      sudo apt remove docker docker-engine docker.io 
      
    2. Now, Install the following packages that are required to the next steps.
      sudo apt update 
      sudo apt install apt-transport-https ca-certificates curl gnupg lsb-release 
      
    3. Configure the Docker’s GPG key on your system.
      curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg 
      

      The Debian users must replace ubuntu with debian.

    4. Then you need to create the Docker repository file. This can be done by running the following command in a terminal window:
      echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] \
       https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | \
       sudo tee /etc/apt/sources.list.d/docker1.list > /dev/null  
      

      The Debian users must replace ubuntu with debian.

    5. Finally, install Docker community edition and other required packages on Ubuntu and Debian systems.
      sudo apt update 
      sudo apt install docker-ce docker-ce-cli containerd.io 
      
    6. Once the installation is complete, you can verify that Docker is installed by running the following command:
      docker --version
      
      Output:
      Docker version 20.10.21, build baeda1f

      This will output the version of Docker that is installed on the system.

    Using Docker on Ubuntu & Debian

    Once Docker is installed, you can use it to create and manage containers on your system. To start a container, use the following command:

    docker run image_name 
    

    This will start a container with the specified image. You can also specify additional options to customize the container, such as port mappings and environment variables.

    Once the container is running, you can use the following command to view its status:

    docker ps
    

    This will display a list of all running containers, including the one that you just started.

    Creating Docker Images

    Docker images are the basis for containers. They are created from a Dockerfile, which is a text file that contains instructions for building the image.

    To create a Docker image, first, create a Dockerfile and save it in the same folder as your application code. The Dockerfile should contain instructions for building the image. For example, the following Dockerfile will create an image with the latest version of Ubuntu and install the Apache web server:

    1
    2
    3
    4
    FROM ubuntu:latest
    RUN apt update && apt install -y apache2
    EXPOSE 80
    CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]

    Once the Dockerfile is complete, you can build the image by running the following command:

    docker build -t image_name  .
    
    Installing and Using Docker on Ubuntu and Debian
    Build docker image

    This will create an image with the specified name.

    Running Docker Containers

    Once an image is created, you can use it to run containers. To start a container, use the following command:

    docker run -d -it image_name 
    
    Installing and Using Docker on Ubuntu and Debian
    Creating docker container from image

    This will start a container with the specified image. The -d parameter runs the container in daemon mode, So you get back to the terminal immediately. You can also specify additional options to customize the container, such as port mappings and environment variables.

    Managing Docker Containers

    Once a container is running, you can manage it using the Docker command-line interface. To view a list of running containers, use the following command:

    docker ps 
    

    This will display a list of all running containers, including the one that you just started.

    Installing and Using Docker on Ubuntu and Debian
    List running docker containers

    To stop a container, use the following command:

    docker stop container_id 
    

    This will stop the specified container.

    You can also view the log output from a running container by using the following command:

    docker logs container_id 
    

    This will output the log output from the specified container.

    You can also delete the Docker container by using the following command:

    docker delete container_id 
    

    This will delete the specified Docker container.

    Docker and Security

    Docker containers are secure by default. Each container is isolated from other containers, making it difficult for malicious code to spread across systems.

    However, it is still important to follow best practices when working with Docker. This includes using only trusted images, running containers with the least amount of privileges, and utilizing security tools such as SELinux and AppArmor to lock down containers.

    Conclusion

    In this article, we discussed how to install and use Docker on Ubuntu, one of the most popular Linux distributions. We discussed the benefits of using Docker, how to install it on Ubuntu, and how to create and manage Docker containers. Finally, we discussed how to ensure the security of your Docker containers.

    If you are looking for an easy and efficient way to manage applications on Ubuntu, then Docker is a great choice. With Docker, you can quickly and easily deploy applications in a secure and consistent manner. So why not give it a try and discover the power of Docker for yourself?

    Container Docker docker ce docker on ubuntu install docker install docker on ubuntu
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    Running a Cronjob Inside Docker: A Beginner’s Guide

    Running a Cronjob Inside Docker: A Beginner’s Guide

    Docker Run: A Beginner’s Guide to Run Docker Containers

    Docker Run: A Beginner’s Guide to Run Docker Containers

    Docker Build: A Beginner’s Guide to Building Docker Images

    Docker Build: A Beginner’s Guide to Building Docker Images

    View 3 Comments

    3 Comments

    1. pegge on July 25, 2019 9:49 am

      how i can uninstall docker ?

      Reply
    2. pradeep varakala on April 10, 2019 7:43 am

      sudo add-apt-repository “deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable”

      while executing above command i am getting error like the following:

      Traceback (most recent call last):
      File “/usr/bin/add-apt-repository”, line 11, in
      from softwareproperties.SoftwareProperties import SoftwareProperties, shortcut_handler
      File “/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py”, line 27, in
      import apt_pkg
      ModuleNotFoundError: No module named ‘apt_pkg’

      can you please give me solution to me query

      Reply
    3. Özkan Şen on February 20, 2019 12:38 am

      or easy way :
      sudo snap install docker

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • How to List Manually Installed Packages in Ubuntu & Debian
    • 10 Bash Tricks Every Developer Should Know
    • How to Validate Email Address in JavaScript
    • Firewalld: Common Firewall Rules and Commands
    • 12 Apk Commands in Alpine Linux Package Management
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.