在VPS上安装Docker,可以参考官方文档。
-
登录到您的 VPS: 使用 SSH 连接到您的 VPS。您可能需要 VPS 提供的 IP 地址和登录凭证。通常使用以下命令:
ssh username@your_vps_ip
其中
username
是您的 VPS 用户名,your_vps_ip
是 VPS 的 IP 地址。 -
检查操作系统版本: 登录后,您可以运行以下命令来检查操作系统版本:
- 对于 Debian/Ubuntu 系统:
lsb_release -a
- 对于 CentOS/RHEL 系统:
cat /etc/redhat-release
- 对于 Fedora 系统:
cat /etc/fedora-release
- 对于其他或通用方法:
uname -a
- 对于 Debian/Ubuntu 系统:
-
更新软件包索引(Ubuntu/Debian):
sudo apt update
-
安装所需的依赖项(Ubuntu/Debian):
sudo apt install apt-transport-https ca-certificates curl software-properties-common
-
添加 Docker 的官方 GPG 密钥:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
-
设置 Docker 仓库: 对于 Ubuntu:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
对于 Debian,替换为相应的 Debian 仓库。
-
再次更新软件包索引:
sudo apt update
-
安装 Docker CE:
sudo apt install docker-ce sudo apt install docker-compose
-
检查 Docker 是否正常运行:
sudo systemctl status docker
或者运行一个测试容器:
sudo docker run hello-world
-
安装 Git(如果尚未安装):
sudo apt install git
-
克隆 GitHub 仓库:
git clone https://github.com/yourusername/yourrepository.git
替换为您的 GitHub 仓库 URL。
-
进入仓库目录:
cd yourrepository
docker exec -it container bash