Docker empowers developers to seamlessly build, test, deploy, and manage applications in isolated environments called containers. This guide simplifies Docker for beginners, providing a breakdown of its architecture and essential commands, along with a some basic commands for Docker.
Understanding Docker’s Architecture:
Docker’s core architecture revolves around five key components:
- Docker Server (Daemon): This background program manages your containers and images. It acts as the engine, responding to commands from the client to create, start, stop, and manage containers.
- Docker Client: Imagine this as your control panel. It’s a command-line interface (CLI) that allows you to interact with the Docker daemon. You use the Docker CLI to send instructions for building, managing, and running containerized applications.
- Container: A container is a lightweight, self-contained unit that packages an application with all its dependencies (code, libraries, runtime) needed to run. Containers share the host operating system’s kernel, making them portable and efficient.
- Image: An image serves as a blueprint for creating containers. It’s a read-only template that contains the instructions and files needed to configure a container. You can think of it as a recipe for building your containerized application.
- Registry: A registry acts as a central repository for storing and sharing Docker images. Docker Hub, a public registry from Docker, offers a vast collection of pre-built images for various applications. You can also create private registries for your own custom images.
Generic Docker Commands
- Build an Image: docker build .
- Build and Tag and Image: docker build -t image_name:tag
- Run an Image: docker run –name containername -p 80:8081 -d imagename
- List the running containers: docker ps
- Stopping a container: docker stop containername
- List the images: docker images
- Removing an image: docker images remove
- Removing a Container: docker rm containername
Docker Commands for Images
Container Lifecycle Management
- docker start container: Initiates a new container based on an existing image.
- docker stop container: Gracefully halts a running container.
- docker pause container: Pauses a container, temporarily suspending all processes.
- docker unpause container: Resumes a paused container, allowing processes to continue execution.
- docker restart container: Restarts a container, effectively stopping and then starting it again.
- docker wait container: Blocks the terminal until the specified container terminates, displaying the exit code.
- docker export container: Exports the contents of a container into a compressed tar archive.
- docker attach container: Attaches your terminal to a running container, enabling you to interact with its processes.
Inspecting Container Details
- docker ps: Lists all currently running containers.
- docker ps -a: Lists all containers, including both running and stopped ones.
- docker diff container: Examines the changes made to a container’s filesystem compared to its original image.
- docker top container: Provides a real-time view of all running processes within a container.
- docker inspect container: Unveils detailed information about a specific container, including its configuration, network settings, and resource usage.
- docker logs container: Retrieves and displays the log messages generated by a container.
- docker stats container: Shows live statistics on a container’s resource consumption, such as CPU, memory, and network bandwidth.
Image Management Techniques
- docker image ls: Lists all images currently available on your Docker host.
- docker image rm image: Removes an image from your local Docker storage.
- docker tag image tag: Assigns a new tag to an existing image, allowing for easier identification and versioning.
- docker history image: Presents the history of an image, revealing the layers that make it up.
- docker inspect image: Delves into the intricate details of an image, including its configuration and creation process.
Reference: https://docs.docker.com/reference/cli/docker/image/build/