Setup Docker Container in Linux – Process

how to use docker

Introduction to Docker

Docker is an open-source platform that enables developers to package applications and their dependencies into lightweight, portable containers. These containers encapsulate everything needed to run an application, including code, runtime, system tools, and libraries, ensuring consistency and reliability across different environments

Setting up Docker and using it for containerization is relatively straightforward, and I’ll walk you through the process step by step:

1. Install Docker

Linux

    • Update your package index:  sudo apt-get update.
    • Install dependencies: sudo apt-get install apt-transport-https ca-certificates curl software-properties-common.
    • Add Docker’s official GPG key: curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -.
    • Add Docker’s repository: sudo add-apt-repository “deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable”.
    • Update your package index again: sudo apt-get update. 
    • Install Docker: sudo apt-get install docker-ce. 
    • Verify Docker installation: sudo docker –version.

    Windows/macOS

    • For Windows and macOS, Docker provides Docker Desktop, which includes Docker Engine, Docker CLI client, Docker Compose, Docker Content Trust, Kubernetes, and Credential Helper. You can download it from the Docker website.

    2. Start Docker

        • On Linux, Docker should start automatically after installation. You can check the status using  sudo systemctl status docker.
        • On Windows or macOS, start Docker Desktop from the installed applications.

      3. Verify Installation

          • Open a terminal (or Command Prompt on Windows) and run docker --version to ensure Docker is installed correctly.

        4. Run Your First Container

            • Pull an image from Docker Hub. For example, to pull the official hello-world image, run: docker pull hello-world
            • Run the container using the pulled image: docker run hello-world

          5. Docker Basics

          • Docker Images: Images are the blueprints for containers. You can pull images from Docker Hub or create your own using Dockerfiles.
            • List downloaded images: docker images.
            • Pull an image: docker pull <image_name>
          • Docker Containers: Containers are instances of Docker images. You can start, stop, and manage containers using Docker commands.
            • List running containers: docker ps.
            • List all containers (including stopped ones): docker ps -a.
            • Start a container: docker start <container_id_or_name>.
            • Stop a container: docker stop <container_id_or_name>.
            • Remove a container: docker rm <container_id_or_name>

          6. Docker Compose (Optional)

          • Docker Compose is a tool for defining and running multi-container Docker applications. It uses YAML files to configure the application’s services, networks, and volumes. You can install Docker Compose separately or use Docker Desktop, which includes it.
            • Create a docker-compose.yml file defining your services.
            • Run docker-compose up to start the services defined in the file.

          Conclusion

          • Setting up Docker and using it for containerization is an essential skill for modern software development and deployment. By following these steps and familiarizing yourself with Docker’s basic commands, you can leverage the power of containerization to streamline your development workflow and deploy applications with confidence. Experiment with different Docker features and explore Docker Hub to discover a vast ecosystem of pre-built images for various use cases.

          Leave a Comment

          Your email address will not be published. Required fields are marked *