0% found this document useful (0 votes)
21 views18 pages

Docker

The document provides an overview of Docker and containerization, explaining what containers and Docker are, along with their benefits. It covers essential commands for managing containers, images, networks, and volumes, as well as the structure of a Dockerfile and the use of Docker Compose for multi-container applications. Additionally, it discusses Docker networking concepts and the importance of volumes for data persistence.

Uploaded by

yahia chammemi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views18 pages

Docker

The document provides an overview of Docker and containerization, explaining what containers and Docker are, along with their benefits. It covers essential commands for managing containers, images, networks, and volumes, as well as the structure of a Dockerfile and the use of Docker Compose for multi-container applications. Additionally, it discusses Docker networking concepts and the importance of volumes for data persistence.

Uploaded by

yahia chammemi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

DOCKER BASICS

DEV OPS
CONTAINERS AND DOCKER BASICS

What is a Container?
Containers are lightweight, standalone, and executable units of software that package
up the application code along with all its dependencies. This ensures that the app runs
consistently across different environments.
What is Docker?
Docker is a platform that enables developers to build, deploy, and manage
containerized applications. Docker makes it easier to isolate applications, manage
dependencies, and ensure consistency from development to production environments.
Why use Docker?
Docker provides benefits such as application portability, faster development cycles,
isolated environments, consistency between development and production, and
resource efficiency compared to traditional virtual machines.
DOCKER HUB & REGISTRIES

Docker Hub
Cloud-based repository for storing and sharing Docker container images.
Allows users to pull pre-built imagesfor projects, speeding up the development process.
Example: docker pull nginx (pulls the NGINX image from Docker Hub)
Push custom-built images to Docker Hub, either for public sharing or privateuse.
Example: docker push username/my-image

Private Docker Registry


Provides more control over image storage by setting up a private registry.
Useful in enterprise environments for securely hosting sensitive applications and images.
Helps ensure security and privacy, preventing images from being exposed to the public.
Example: docker run -d -p 5000:5000 --name registry registry:2 (runs a private registry on
localhost)
DOCKERIZED APPLICATIONS

What Does "Dockerizing" Mean?


Packaging an application and its dependencies into a Docker container.

Steps to Dockerize a Simple App:


1. Create a Dockerfile to define the environment.
2. Copy the app’s source code into the container.
3. Install dependencies (e.g., Python, Node.js).
4. Expose necessary ports for the app to interact with the outside world.
INSTALLING DOCKER

Terminal

$ sudo apt update


$ sudo apt install apt-transport-https ca-certificates curl software-properties-common
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
$ sudo apt update
$ sudo apt install docker-ce
$ sudo usermod -aG docker $YOUR_USERNAME
$ docker run hello-world
ESSENTIAL DOCKER COMMANDS

Container Management Commands

Terminal Terminal Terminal

$ docker run <container_name> $ docker ps $ docker stop <container_name>

Run a container List running containers Stop running containers

Terminal Terminal

$ docker exec -it <container_id> $ docker logs <container_id>


bash

Execute commands inside a container View logs of container


ESSENTIAL DOCKER COMMANDS

Image Management Commands

Terminal Terminal Terminal

$ docker pull <Image_name> $ docker rmi <Image> $ docker build

Download an image Remove images Build a custom image from a Dockerfile


ESSENTIAL DOCKER COMMANDS

Docker Networks Management Commands

Terminal Terminal Terminal

$ docker network create $ docker network ls $ docker network inspect


<network_name> <network_name>

Create a network View Available Networks Inspect a Network

Terminal

$ docker network rm
<network_name>

Remove network
ESSENTIAL DOCKER COMMANDS

Docker Volumes Management Commands

Terminal Terminal Terminal

$docker run -d --name


$ docker volume create $ docker volume ls <container_name> -v
<volume_name> <volume_name>:/path/in/contai
ner <image_name>
Create a volume List volumes Use a Volume in a Container

Terminal Terminal

$ docker volume inspect $ docker volume rm


<volume_name> <volume_name>

Inspect a Volume Remove a Volume


UNDERSTANDING DOCKERFILE

Dockerfile

A Dockerfile is a text file # Use an official base image


that contains instructions FROM python:3.10-slim
# Set the working directory inside the container
to build a Docker image. It WORKDIR /app
automates the process of # Copy the current directory contents into the container at /app
COPY . .
creating Docker images by # Install any needed dependencies specified in requirements.txt
defining all dependencies, RUN pip install openpyxl
# Make port 80 available to the world outside this container
configurations, and steps EXPOSE 80
to set up the application # Define environment variable
ENV NAME World
environment. # Run the application
CMD ["python", "app.py"]

Example of Dockerfile Structure


UNDERSTANDING DOCKER-COMPOSE

What is Docker Compose?


Docker Compose is a tool for defining and running multi-container Docker
applications. It uses a docker-compose.yml file where services, networks, and
volumes can be defined and managed as a single application stack.
Key Features:
Define multi-container applications (e.g., web, database, cache services) and manage
them with simple commands. Docker Compose allows easy scaling, network
configuration, and dependency management across containers.
UNDERSTANDING DOCKER-COMPOSE

version: Defines the version of the Docker Compose file


format (in this case, version 3).
docker-compose.yml services: Specifies the services that make up the
application. In this example, there’s only one service called
version: '3' app.
services: app: The name of the service.
app: image: Specifies the base image to use (python:3.10-slim).
image: python:3.10-slim container_name: Sets a custom name for the container
container_name: my_app (my_app).
working_dir: /app working_dir: Specifies the working directory inside the
volumes: container (/app).
- .:/app volumes: Mounts the current directory on the host machine
ports: (.) to /app in the container.
- "8080:8000" ports: Maps port 8080 on the host to port 8000 on the
command: python app.py container.
command: Specifies the command to run (python app.py),
which will start your application.
NETWORKING IN DOCKER
Docker networking allows containers to communicate
with each other and with the external world. It
handles the interaction between containers, whether
they are on the same host or across different hosts

Basic Networking Concepts


Docker handles container-to-container communication.
Containers on the same network can communicate using container names.
Containers can be isolated for enhanced security.
NETWORKING IN DOCKER
Network Types
Bridge Network (default):
Containers communicate within the same network.
Useful for single-host setups.
Example: docker network create my_bridge_network
Host Network:
Containers use the host’s network stack, bypassing Docker's virtual network.
Offers better performance, but less isolation.
Example: docker run --network host
Overlay Network:
Allows communication across multiple Docker hosts (used in Docker Swarm).
Enables seamless multi-host networking.
Example: docker network create -d overlay my_overlay_network
NETWORKING IN DOCKER

Container Communication
User-Defined Networks:
Provides better control over container communication.
Containers on the same user-defined network can communicate using network names.
Example: docker run --network my_network
Connecting Containers on the Same Network:
Containers on the same network can communicate directly.
Example: docker run -d --name web --network my_network nginx
Exposing Containers to External World (Port Mapping):
Map container ports to the host system for external access.
Example: docker run -d -p 8080:80 nginx (Access via localhost:8080)
DOCKER VOLUMES

What Are Volumes?


Volumes are used to store data generated by Docker containers.
They persist data beyond the container lifecycle, ensuring data is not
lost when containers are removed.
Independent of the container, volumes help manage important data
that needs to survive container restarts, removals, or upgrades.
DOCKER VOLUMES

Types of Volumes
Bind Mounts:
Mount a specific host directory directly into the container.
Provides direct access to files on the host machine.
Example: docker run -v /host/path:/container/path
Named Volumes:
Managed by Docker and stored in /var/lib/docker/volumes/.
Easier to manage since Docker controls the storage location.
Example: docker volume create my_volume then docker run -v
my_volume:/container/path
THANK YOU FOR YOUR
ATTENTION

You might also like