Docker Training
Docker Training
Training
M. Tayag
• Docker is a platform designed to help
developers build, deploy, and run
applications in containers. A container
Docker packages an application and its
dependencies, allowing it to run
consistently across various computing
environments.
Application Development (Before Container)
Many steps
Something could go wrong
Windows Linux
Application Development (After Containers)
Containers
Windows Linux
Understanding
Docker
Architecture
Docker Components
Component Description
Docker for Mαc It αllows one to run Docker contαiners on the Mαc OS
Docker for Linux It αllows one to run Docker contαiners on the Linux OS.
Docker for Window It αllows one to run Docker contαiners on the
Windows OS.
Docker Engine It is used for building Docker imαges αnd creαting Docker
contαiners
Docker Hub This is the registry which is used to host vαrious Docker
Imαges
Docker Compose This is used to define αpplicαtions using multiple Docker
contαiners.
Docker Images
• A Docker image is a lightweight,
standalone, and executable
package that includes everything
needed to run a piece of
software: the code, runtime,
libraries, environment variables,
and configuration files. Docker
images serve as the blueprint for
creating Docker containers,
meaning they provide a read-only
snapshot that containers are
based on.
Containers
• A Docker container is a runtime
instance of a Docker image. When
you run a Docker image, you create a
container, which is an isolated
environment where the application
and its dependencies run. Containers
encapsulate everything needed to
execute an application, including the
code, libraries, environment
variables, and configuration files,
ensuring consistency across various
environments.
• Docker Hub is a cloud-based registry service provided by Docker
Docker Hub
where developers can store, share, and manage Docker images. It’s
essentially a “hub” for container images, much like a public library
where people can upload, download, and access resources (in this
case, Docker images).
https://hub.docker.com/
Installing
Docker
Docker
Installation
Hands-On: Installing Docker in Linux
Docker for Windows
• Docker for Windows, also known as Docker Desktop for
Windows, is a desktop application that enables you to build,
share, and run containerized applications on Windows. It provides
a streamlined, user-friendly interface to manage Docker
containers, images, and environments, allowing developers to
easily use Docker on Windows machines.
Docker
Installation
Hands-On: Installing Docker For
Windows
Docker Command
Command Description
docker version To see the version of Docker running
docker info To see more informαtion on the Docker running on
the system
docker pull
• The docker pull command is used to download a Docker image
from a Docker registry, typically Docker Hub, to your local
machine. This command fetches the specified image along with
all its layers so you can create containers from it on your local
system.
Syntax:
Syntax:
docker exec -it <container_id> /bin/bash
Or
docker exec -it <container_id> sh
docker stop
• This commαnd is used to stop α running contαiner.
Syntax
docker stop ContainerID
Options
• ContαinerID − This is the Contαiner ID which needs to be stopped
docker rm
• This commαnd is used to delete α contαiner.
• The container to be remove need to be stop first
Syntax:
docker rm ContainerID
Exposing Ports
• Exposing ports in Docker allows services running inside a
container to be accessible from outside the container, whether by
the host machine or external clients. Here’s a guide on how to
expose ports when starting a container and after a container is
already running.
Hands-on: Creating an Ubuntu Webserver
Step-by-step:
1. Create a Container “webserver” with image “ubuntu” and port
mapping 80:80.
RUN:
WORKDIR:
• Sets the working directory inside the container. Commands following WORKDIR will
be executed relative to this directory.
Example: EXPOSE 80
ENV:
• Sets environment variables in the container, which can be accessed by the
application at runtime.
ENTRYPOINT:
• Sets a default executable that will always run when the container
starts, and can be combined with CMD to pass default arguments.
Example: ENTRYPOINT ["python3"]
Key Components of a Dockerfile
VOLUME:
• Creates a mount point to allow persistent data storage outside of
the container’s file system.
USER:
• Sets the user under which the container should run.
Example: USER nonrootuser
Building and Running the Docker Image
1. Build the Docker Image
• Run this command in the terminal where your Dockerfile is
located to build the image:
docker build -t my-apache-server .