Understanding the Components of Containers

Summary: Linux distributions and application projects have official repositories on the Docker Hub Registry. In addition to the Docker container images themselves, in most cases, you can also find instructions for using these images and the Dockerfiles used to build them on the Docker Hub Registry .

This section of the book is excerpted from Chapter 1, Section 1.2 of the book "Docker Containers: Building and Deploying with Kubernetes, Flannel, Cockpit, and Atomic" by the asynchronous community, author: [US] Christopher Negus (Christopher Negus) , more chapters can be viewed by visiting the public account of Yunqi Community "Asynchronous Community"

【Understanding the Components of Containers】 Understand the composition of the container


Docker is a container format developed by the Docker project. The docker command can run, stop, start, investigate, and manipulate containers. The docker command can also run as a service daemon, handling requests to manage Docker containers. By default, this Docker service will fetch the images you request from the Docker Hub Registry. While you don't need to know more to get started, some additional information is given in turn.
1.2.1 The Docker Project The
Docker Project provides a hub for Docker development. It calls Docker "an open platform for distributed application developers and system administrators" that aims to simplify application development and distribution.
Solomon Hykes is the founder and CTO of Docker. He contrasts what Docker is going to do in the software industry to what physical containers are doing for the shipping industry. Whether shipping cars, drums, boxes, or pianos, as long as standard containers are used to transport these different types of items, the tools used to ship and handle them can also be standardized.
So, at its core, the Docker project provides a format for software containers and creates a simple infrastructure for software that uses that format. As the project progressed, it began to move beyond its initial focus on the stable Docker format and providing tools to manage individual containers.
Today, the Docker project is expanding its scope to include configuration and orchestration tools to help people deploy and manage groups of containers. The project also looks at ways to manage computing resources and provide highly available ways to help run Docker containers. As these tools become available, they will have to go head-to-head with the more mature container orchestration tools being developed by companies like Google and Red Hat, including those from the Kubernetes projects covered in this book.
However, the biggest achievements of the Docker project so far are the Docker container format, tools for managing individual containers, and the ability to pull and push Docker container images between the Docker client and the registry. The central registry for Docker project management is called the Docker Hub Registry.

【Understanding the Components of Containers】1.2.2 Docker Hub Registry


The Docker Hub Registry provides a place for individuals and organizations to store and develop their Docker container images. When Docker is installed on your Linux system, if the Docker container image you request is not already on your system, by default Docker will look in the Docker Hub Registry.
Figure 1-1 shows the Docker Hub Registry page.

Figure 1-1 Docker Hub Registry holds thousands of Docker images
By registering a Docker user account, you can have your own Docker repository where you can push Docker container images to. After that, you can pull these images from any system running Docker as long as you have an internet connection.
Linux distributions and application projects have official repositories on the Docker Hub Registry. In addition to the Docker container images themselves, in most cases, you can also find instructions for using these images and the Dockerfiles used to build them on the Docker Hub Registry . For container images that you don't want to share publicly, there are also ways to create your own Docker Registry, which you can use to keep images privately or purchase secure container storage directly from the Docker project.
You may have noticed that words like "image" and "container" appear when describing the format Docker uses to store and transport software. Understanding the difference between images and containers is critical when using Docker.
1.2.3 Docker images and containers
The purpose of containerization is to bring together all the components needed for an application to run in a single and independent unit. For Docker , this unit is called a Docker image. Inside the image is the application the container is to run and the libraries, configuration files, executables, or other components that the application needs to execute.
An image is a static unit that is either in the repository or the local filesystem where Docker is installed, waiting to be run. Unlike storing a Docker image in a repository, when a Docker image is saved to the filesystem, it is saved as a tarball file. This tarball can be transferred like any other file, which can then be imported and run as a container on the local system running Docker.
Major Linux distributions like Red Hat Enterprise Linux, Ubuntu, Fedora, and CentOS all provide official base images that you can use to build your own Docker images. Even if you're not a programmer, you can grab a base image, add existing applications to it, and make it your own. To do this just create a Dockerfile and run the docker build command on it.
The term Docker container refers to a running instance of a Docker image, or more precisely, an instance of a running image, as it may be running, paused, or stopped at the moment. The distinction between images and containers is critical when getting started with Docker. The reason you need to understand this difference is that there are different commands for working with images and working with containers.
For example, to view a list of images on your local system, enter docker images; to view a list of running containers, enter docker ps (or docker ps -a to view images that are no longer running but are still on your system) list of containers).
To run a container from an image, use the docker run command. To stop a running container, use the docker stop command. After the container is stopped, the stopped container can be started again using the docker start command. Just to pause all processes in the container, use the docker pause command. Then type docker unpause to start the paused container again. Remember, docker run runs a new container from the original image, while docker start restarts a container from the state it was in when it was stopped (e.g., software you added or files you modified are still there).
When working with containers, you will notice that all the examples given have one thing in common. Each of them is invoked using the docker command.
1.2.4 The docker command
The docker command is the main command you use to work directly with Docker containers and images. In fact, in some packages of the Docker software, docker is just one of the few executable commands.
Once the Docker software is installed as described in Chapter 2, simply start the Docker service to start using docker commands. A nice feature built into the docker command is tab autocompletion (if you're running Docker from the default bash shell). So, once the Docker service is running, you can enter docker as the root user, followed by pressing the Tab key twice to see the available docker subcommands:
# docker < Tab >
attach exec inspect port rmi tag
build export kill ps run top
commit help load pull save unpause
cp history login push search version
create images logout rename start wait
diff import logs restart stats
events info pause rm stop
Because most of the chapters in Part 2 of this book are dedicated to how docker works with these subcommands, I won't spend too much time showing how they all work. Instead, I'll outline what you can do with them.
Find information about Docker components: Use docker version to display version information for Docker features. Use docker info to view information about the system running Docker. docker help to see the commands and options that can be used with docker commands. Use docker history to display the history of the image. Use docker inspect to view information about an image or container. Use docker port to list port mappings for containers.
Manipulate running containers: Use docker ps to list running containers. Use docker attach to attach another command to the running container. Use docker exec to execute commands in a running container. Use docker inspect to inspect the container's metadata. Use docker cp to copy files from the container to the host system. Use docker diff to check the changes a container has made to its filesystem since it was started.
Manipulate images: Use docker images to list images on your system. Use docker run to run the image. Use docker pull to pull images from the registry to the local system. Use docker push to push the image to the registry. Use docker save to save the image as a tarball . Use docker load to load a local image from a tarball file. Use docker export to export the filesystem from the container as a tarball file of the local system.
Operate the Docker registry: Use docker search to search the registry for images. Log in to the Docker Hub Registry using docker login (you can use your own account to push and pull images). Use docker logout to log out from the Docker Hub Registry.
Modify an existing image: Use docker tag to add a name to the image. Use docker rename to change the name of the image.
Modify the state of a container: Stop a running container with docker stop. Use docker start to start a stopped container. Use docker pause to pause the container. Use docker unpause to restart a paused image. Use docker kill to send a kill signal or other signal to the container. Stop and restart the container with docker restart.
View Docker activity: Use docker events to view Docker server events. Use docker top to view the container's process activity. Use docker logs to view log messages produced by the container. Use docker stats to view CPU and memory usage statistics for containers. Use docker wait to watch the container until it stops, then print its exit code.
Create images and containers: Use docker build to build images from scratch. Use docker commit to create an image from a container. Use docker create to create a container from an image without running it. Use docker import to import the filesystem into the image.
Remove containers and images: Use docker rm to remove stopped containers. Use docker rmi to remove the image.
Although Docker is designed to help you get containers up and running with minimal hassle, this book is here to guide you through your first experience with Docker and point out interesting features that you might not be able to discover on your own. After that, the book takes you into some of the less-drawn waters in Docker - related to the deployment and management of multiple containers. In other words, this book provides you with a way to go on a Docker adventure.


Copyright statement: The content of this article is contributed by Alibaba Cloud real-name registered users. The copyright belongs to the original author. The Alibaba Cloud developer community does not own the copyright and does not assume the corresponding legal responsibility. For specific rules, please refer to the " Alibaba Cloud Developer Community User Service Agreement " and " Alibaba Cloud Developer Community Intellectual Property Protection Guidelines ". If you find any content suspected of plagiarism in this community, fill out the infringement complaint form to report it. Once verified, this community will delete the allegedly infringing content immediately.

Related Articles

Explore More Special Offers

  1. Short Message Service(SMS) & Mail Service

    50,000 email package starts as low as USD 1.99, 120 short messages start at only USD 1.00