π¦ 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
- What is Docker?
- Key Features
- Installation
- Basic Commands
- Getting Started with Docker
- 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:
- Update Package Index:
- Install Required Packages:
- Add Dockerβs Official GPG Key:
- Set up the Docker Repository:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
- Install Docker Engine:
- Verify Docker Installation:
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:
- Run a Sample Container:
This command pulls the hello-world
image from Docker Hub and runs it in a container, printing a confirmation message.
- List Running Containers:
- List All Containers (including stopped):
- Stop a Running Container:
- Remove a Container:
π Getting Started with Docker
- 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"]
- Build an Image:
- Run a Container: