Docker Tutorial for Beginners [FULL COURSE in 3 Hours]
What You Will Learn
- Understand the basic concepts of Docker and how it solves problems in the development and deployment process
- Learn how to use Docker in practice by going through a complete workflow with a demo project
- Understand the difference between Docker and virtual machines, and how to use Docker commands to start and stop containers
Key Concepts
Docker is a way to package applications with everything they need inside of that package, including dependencies and configuration, making it portable and easy to share. Containers live in a container repository, which is a special type of storage for containers. Docker images are made up of layers, and the size of Docker images is much smaller compared to virtual machine images. Docker virtualizes the applications layer, whereas virtual machines virtualize the complete operating system.
Code Examples
docker run -d -p 6000:6379 --name redis_latest redis:latest
This command starts a new Redis container from the latest Redis image, maps port 6379 inside the container to port 6000 on the host, and names the container “redis_latest”.
version: '3'
services:
mongodb:
image: mongodb
ports:
- "27017:27017"
environment:
- ROOT_USERNAME=admin
- ROOT_PASSWORD=password
container_name: db
network_mode: Network
This is an example of a Docker Compose file that defines a service named “mongodb” with the specified image, ports, environment variables, and network mode.
Lesson Summary
In this lesson, we learned about the basics of Docker and how it can be used to simplify the development and deployment process. We learned about the concept of containers and how they are stored in a container repository. We also saw how Docker can be used to improve the development process by providing a consistent and isolated environment for applications to run in. Additionally, we learned about the difference between Docker and virtual machines, and how Docker virtualizes the applications layer, whereas virtual machines virtualize the complete operating system. We also went through a practical example of how to use Docker in a local development process, and how to use Docker Compose to manage multiple containers.
Practice Exercise
Create a new Docker container from the official PostgreSQL image, and map port 5432 inside the container to port 5432 on the host. Use the -d flag to run the container in detached mode, and name the container “postgres_dev”.
What Is Next
In the next lesson, we will learn about Docker volumes and how to use them to persist data between container restarts. We will also learn about Docker networking and how to use it to connect multiple containers together.