今天记录下在一台新的linux服务器上安装docker。
linux环境
Welcome to Ubuntu 18.04.5 LTS (GNU/Linux 4.15.0-144-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
Welcome to Alibaba Cloud Elastic Compute Service !
安装docker命令
sudo apt-get update
# 允许apt通过HTTPS使用存储库
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
# 安装GPG证书
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
# 写入软件源
sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
# 更新并安装Docker-CE
sudo apt-get -y update
sudo apt-get -y install docker-ce
docker-ce后面不指定版本默认是安装最新的
yum list docker-ce --showduplicates | sort -r
docker-ce.x86_64 3:18.09.1-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.0-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.1.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.0.ce-3.el7 docker-ce-stable
sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
安装完成后设置开机自启动
sudo systemctl enable docker # 开机自动启动
sudo systemctl start docker # 启动docker
查看docker的信息
docker info
这个步骤没有错误,亲测有效,到此就安装完成了,接下来就可以开始你的docker服务之旅了。
docker服务可以用dockerfile来管理容器,也可以安装docker-compose来管理,我自己是用docker-compose的。
下面介绍下docker-compose安装使用
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
docker-compose版本可以在https://github.com/docker/compose/releases上查看。
安装完后就可以使用创建docker-compose.yml文件
version: "2.0"
services:
wj_redis:
build : ./redis
command : redis-server --requirepass 123456
restart : always
container_name : wj_redis
ports:
- "10000:6379"
这里创建一个redis容器
执行命令
docker-compose ps--查看容器列表
docker-compose up wj_redis --创建并启动容器
就行了。