Docker 是一个开源的应用容器引擎,可以打包您的应用程序以及其运行时环境到一个可移植的容器中。以下是 Docker 的基本教程。

安装 Docker

在大多数 Linux 发行版上,您可以通过包管理器来安装 Docker。以下是在 Ubuntu 上安装 Docker 的命令:

sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io

安装完成后,您可以通过以下命令启动 Docker 服务:

sudo systemctl start docker

运行第一个容器

打开终端,并运行以下命令来运行一个名为 hello-world 的 Docker 容器:

docker run hello-world

您将看到以下输出:

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker daemon pulled the "hello-world" image from Docker Hub.
 2. The Docker daemon created a new container from that image which runs as a command line interface.
 3. The Docker daemon executed the command (echo 'Hello from Docker!') in the container.

容器操作

以下是一些基本的 Docker 容器操作:

  • 列出所有容器docker ps
  • 查看容器日志docker logs <container_id>
  • 启动容器docker start <container_id>
  • 停止容器docker stop <container_id>
  • 删除容器docker rm <container_id>

更多资源

如果您想了解更多关于 Docker 的信息,请访问我们的 Docker 教程 页面。

Docker 图标