Docker is a platform that simplifies the development, deployment, and running of applications using containerization. Containers are lightweight, portable, and ensure consistency across various environments. This guide will cover the basics of Docker and include hands-on lab exercises to help you practice.
Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers package an application and its dependencies into a single unit that runs consistently on any environment.
docker --version
: Check Docker version.docker pull <image>
: Download an image from Docker Hub.docker images
: List available Docker images.docker run <image>
: Create and start a container from an image.docker ps
: List running containers.docker stop <container_id>
: Stop a running container.docker rm <container_id>
: Remove a stopped container.docker rmi <image_id>
: Remove a Docker image.2. Verify Installation:
docker pull hello-world
to download a test image from Docker Hub.2. List Docker Images:
docker images
to see the list of images on your system.3. Run a Docker Container:
docker run hello-world
to create and run a container from the hello-world image.docker run -it ubuntu
.apt-get update && apt-get install -y curl
.2. List Running Containers:
docker ps
to see currently running containers.3. Stop and Remove a Container:
docker stop <container_id>
.docker rm <container_id>
.Create a file named Dockerfile
with the following content:
FROM ubuntu
RUN apt-get update && apt-get install -y curl
CMD ["bash"]
docker build -t my-ubuntu-image .
2. Run Your Custom Image:
docker run -it my-ubuntu-image
.3. Remove Docker Images:
docker images.
docker rmi <image_id>
.docker search <image_name>
.2. Push an Image to Docker Hub:
docker login
.docker tag my-ubuntu-image <username>/my-ubuntu-image
.docker push <username>/my-ubuntu-image
.3. Pull Your Image from Docker Hub:
docker pull <username>/my-ubuntu-image
.Understanding these Docker fundamentals and completing the lab exercises will give you a solid foundation in containerization. Docker allows you to manage applications in a consistent environment, making development and deployment more efficient. Continue practicing these commands and concepts to build your expertise.