Skip to content

πŸ“¦ Docker: Introduction Tutorial

Welcome to the Docker introduction tutorial! Docker is a powerful platform designed to automate the deployment, scaling, and management of applications using containerization. In this tutorial, we'll cover the basics of Docker, including installation, key features, and basic commands to get you started.

πŸ“‘ Table of Contents

  1. What is Docker?
  2. Key Features
  3. Installation
  4. Basic Commands
  5. Getting Started with Docker
  6. Further Reading

πŸ€” What is Docker?

Docker is a containerization platform that allows developers to package applications and their dependencies into containers. Containers are lightweight, portable, and provide a consistent environment for running applications across different systems.

By using Docker, you can ensure that your application runs the same way in development, testing, and production environments, regardless of the underlying system.

🌟 Key Features

  • Isolation: Containers run in isolated environments, ensuring that applications do not interfere with each other.
  • Portability: Docker containers can run on any system that supports Docker, making it easy to move applications between environments.
  • Efficiency: Containers share the host OS kernel, making them more efficient than traditional virtual machines.
  • Version Control: Docker images can be versioned and managed through Docker Hub or private registries.

πŸ› οΈ Installation

For Ubuntu/Linux:

  1. Update Package Index:
sudo apt-get update
  1. Install Required Packages:
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
  1. Add Docker’s Official GPG Key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  1. Set up the Docker Repository:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
  1. Install Docker Engine:
sudo apt-get update
sudo apt-get install docker-ce
  1. Verify Docker Installation:
    docker --version
    

For Windows/Mac:

  • Download and install Docker Desktop from the Docker website.
  • Follow the installation instructions for your operating system.

πŸ’» Basic Commands

  • Verify Docker Installation:
docker --version
  • Run a Sample Container:
docker run hello-world

This command pulls the hello-world image from Docker Hub and runs it in a container, printing a confirmation message.

  • List Running Containers:
docker ps
  • List All Containers (including stopped):
docker ps -a
  • Stop a Running Container:
docker stop <container_id>
  • Remove a Container:
    docker rm <container_id>
    

πŸš€ Getting Started with Docker

  1. Create a Dockerfile: A Dockerfile is a text document that contains all the commands to build a Docker image. Here’s a simple example:
# Use an official Python runtime as a parent image
FROM python:3.8-slim

# Set the working directory in the container
WORKDIR /app

# Copy the current directory contents into the container at /app
COPY . /app

# Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

# Make port 80 available to the world outside this container
EXPOSE 80

# Define environment variable
ENV NAME World

# Run app.py when the container launches
CMD ["python", "app.py"]
  1. Build an Image:
docker build -t my-python-app .
  1. Run a Container:
    docker run -p 4000:80 my-python-app
    

πŸ“š Further Reading