How to Download and Run Docker

When I introduced hummingbot, someone asked me how to run Docker and how to run it on a persistent server. Today’s article will teach you how to install and run Docker. Since Windows and macOS have desktop versions of Docker, we’ll focus on operating it on Linux, which doesn’t have a graphical interface.

在之前介绍hummingbot的时候,就有人问我,Docker怎么运行?怎么在持久化服务器上运行?今天的文章教大家如何安装运行Docker.由于Windows和macOS有桌面版本Docker,所以我们重点讲在没有图形界面的Linux上如何操作.

Official website/官网

Running Docker on a persistent server can drastically improve your workflow, especially if you need long-running services or automated tasks. The first step is setting up a stable Linux environment, usually a server edition without a graphical interface.

在持久运行的服务器上运行 Docker 可以显著提升你的工作流程,尤其是当你需要长时间运行的服务或自动化任务时。第一步是搭建一个稳定的 Linux 环境,通常使用没有图形界面的服务器版本。

For the use of Docker, VPN is an essential tool in countries where the network is restricted. In previous articles, I have also taught you how to set up openVPN and V2ray nodes. However, if you are using a public network server in an available area, you do not need to configure a proxy..

对于docker的使用,在网络被限制的国家,VPN是必不可少的一个工具.之前的文章我也曾教过大家搭建openVPNV2ray节点. 不过,如果你使用的是可用地区的公网服务器,那么你不需要配置一个代理.

1: Install a Lightweight Linux Distribution / 安装轻量级 Linux 发行版

Whether it is your own home server or a purchased public network server, you need choose a server-focused Linux distribution like Ubuntu Server, Debian, or CentOS. These distributions are optimized for performance and minimal resource usage, ideal for headless servers. Here we recommend you to use the Debian/Ubuntu series of Linux distributions.

无论是自己家里的服务器还是购买的公网服务器,你需要选择一个面向服务器的 Linux 发行版,如 Ubuntu Server、Debian 或 CentOS。这些发行版针对性能和最小资源消耗进行了优化,非常适合无图形界面的服务器。这里推荐大家使用Debian/Ubuntu系列的Linux发行版.

2: Access the Server via SSH / 通过 SSH 访问服务器

Cloud servers generally have SSH services, and private key login is required. Simply load the private key file directly from the SSH software. For terminal commands, use:

对于云服务器,一般都有SSH服务,而且是使用私钥登陆,SSH软件直接加载私钥文件即可,终端命令的话使用:

ssh -i yourprivatekeyfile username@your_ip

On a server you install yourself, you typically log in using a password. The command is:

在自己安装的服务器上,通常使用密码登陆,命令为:

ssh username@your_ip

It is more convenient to operate on SSH software. I take Tabby as an example. The operation screenshots are as follows:

在SSH软件上操作更加方便,我以Tabby为例,操作截图如下:

3: Install Docker / 安装 Docker

Before installing Docker, ensure your system packages are up-to-date:
在安装 Docker 之前,请确保系统软件包是最新的:

sudo apt update && sudo apt upgrade -y

Install Docker using the official repository to get the latest stable version:
使用官方仓库安装 Docker,以获得最新稳定版本:

sudo apt install docker.io -y
sudo systemctl enable docker
sudo systemctl start docker
sudo usermod -aG docker $USER

After adding your user to the Docker group, log out and back in for changes to take effect.
将用户添加到 Docker 用户组后,退出并重新登录以使更改生效。

4.Running Containers / 运行容器

You can now pull images and run containers. For example, to run a persistent Nextcloud instance:
现在你可以拉取镜像并运行容器。例如,要运行一个持久的 Nextcloud 实例:

docker run -d \
  --name nextcloud \
  -p 8080:80 \
  -v /srv/nextcloud:/var/www/html \
  nextcloud

At this time, you can also follow my previous tutorial to install hummingbot.

这时候,你也可以跟着我之前的教程安装hummingbot.

5.Managing Docker Without GUI /无图形界面管理 Docker

Use commands like docker ps, docker logs, and docker exec to monitor and interact with containers. Consider installing docker-compose for multi-container setups.

使用 docker psdocker logsdocker exec 等命令来监控和管理容器。对于多容器环境,可以考虑安装 docker-compose

6.Tips for Persistent Servers / 持久运行服务器小技巧

  • Always enable automatic updates for security. / 始终启用自动更新以保证安全。
  • Use swap space or optimize RAM usage. / 使用交换空间或优化内存使用。
  • Set up monitoring tools like htop, netdata, or glances. / 配置监控工具,如 htopnetdataglances

Conclusion / 总结

Running Docker on a headless Linux server is efficient and stable. By mastering SSH, command-line management, and Docker commands, you can maintain long-running applications without relying on a GUI.

在无图形界面的 Linux 服务器上运行 Docker 高效且稳定。通过掌握 SSH、命令行管理和 Docker 命令,你可以在不依赖 GUI 的情况下维护长时间运行的应用程序。

留下评论

您的邮箱地址不会被公开。 必填项已用 * 标注