Ubuntu 简明教程
Ubuntu - Docker
Docker 是一个容器服务,允许用户在主操作系统上作为容器运行应用程序甚至操作系统。 Containers 是一项全新且令人振奋的技术,在过去几年中不断发展,并被许多主要组织采用。
Docker is a container service which allows one to run applications or even operating systems on a host operating system as containers. Containers are a new and exciting technology that has evolved over the last couple of years and being adopted by a lot of key organizations.
Docker 是一个为应用程序开发这些特殊容器的公司。Docker 的官方网站是 {s4}
Docker is a company that develops these special containers for applications. The official website for Docker is https://www.docker.com/

作为一项练习,我们来在 Ubuntu 系统上安装一个 CentOS 容器。CentOS 是一个基于 Red Hat 的 Linux 操作系统。因此,我们将在 Ubuntu 之上运行 CentOS 系统。以下是实现这一点的步骤。
As an exercise, let’s install a CentOS container on an Ubuntu system. CentOS is a Linux-based operating system from Red Hat. Thus, we will be running the CentOS system on top of Ubuntu. Following are the steps to have this in place.
Step 1 - 第一步是在 Ubuntu 服务器上安装 Docker 应用程序。因此,在 Ubuntu 测试服务器上,运行以下命令以确保已更新操作系统。
Step 1 − The first step is to install the Docker application on Ubuntu server. Thus on the Ubuntu test server, run the following command to ensure that OS updates are in place.
sudo apt-get update

Step 2 - 在处理完所有更新后,发出以下命令来安装 Docker。
Step 2 − Once all updates have been processed, issue the following command to get Docker installed.
sudo apt-get install -y docker.io

Step 3 - 在安装完 Docker 软件包后,我们应当收到一个输出消息,该消息表明 Docker 进程已启动并且正在运行。Docker 进程称为 Docker 引擎或 Docker 守护程序。
Step 3 − Once the Docker packages are installed, we should receive an output message stating that the Docker process has started and is running. The Docker process is known as the Docker engine or Docker daemon.
Step 4 - 要查看正在运行的 Docker 版本,发出 Docker info 命令。
Step 4 − To view the version of Docker running, issue the Docker info command.

Step 5 − 下一步是在 Ubuntu 上安装我们的 CentOS 镜像。
Step 5 − The next step is to install our CentOS image on Ubuntu.
Docker 有一个称为 Docker 集线器的特殊站点,用于存储为 Docker 预构建的镜像。该站点的链接为 https://hub.docker.com/
Docker has a special site called the Docker hub, which is used to store pre-built images for Docker. The link to the site is https://hub.docker.com/
Step 6 − 进行一个快速和简单的登录过程,以能够登录站点并查看所有可用的 Docker 镜像。
Step 6 − Do a quick and simple sign-in process to be able to log into the site and see all the available Docker images.

Step 7 − 登录后,单击“浏览”按钮以查看所有可用的 Docker 镜像。
Step 7 − Once logged in, click the Explore button to see all the available Docker images.

需要了解的两个重要点是 −
The two important points to note are −
-
The Docker pull command. This is the command to install the Docker image on Linux box.
-
The Docker details for the various versions of CentOS.

Step 8 − 在 Ubuntu 容器上,运行命令。
Step 8 − On Ubuntu box, run the command.
sudo docker pull centos:latest
Docker 组件下载开始,同时 CentOS Docker 已下载。Docker 镜像的名称为 centos:latest,这意味着我们拥有最新的 CentOS Docker 镜像。
The download of the Docker component starts and the CentOS Docker is downloaded. The name of the Docker image is centos:latest, which means that we have the latest Docker image for CentOS.
Step 9 − 要查看所有已安装的 Docker 镜像,请发出命令
Step 9 − To see all the Docker images installed, issue the command
sudo docker images
在下图中,我们可以看到 Docker 镜像的大小仅为 196.8 MB,这是 CentOS 的子集,现在在 Ubuntu 系统上运行。
In the following screenshot, we can see that the Docker image is just 196.8 MB in size, and this is the subset of the CentOS which now runs on Ubuntu system.

Step 10 − 要启动 CentOS,我们需要向操作系统发出命令以启动线程。我们可以通过运行以下命令来完成此操作。
Step 10 − To start CentOS, we need to issue a command to the OS to get a thread started. We can do this by running the following command.
sudo docker run -it centos /bin/bash
以上命令执行以下操作 −
The above command does the following things −
-
Runs the CentOS Docker image.
-
Runs the image in interactive mode by using the -it option.
-
Runs the /bin/bash command as the initial process.