centos搭建docker及docker-compose
2019-07-27 本文已影响0人
闲睡猫
用yum安装docker
$ sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
$ sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
$ sudo yum install docker-ce -y
$ sudo systemctl start docker # 启动docker
$ sudo docker run hello-world # 第一个实例
查看 docker 版本
$ docker -v
Docker version 19.03.1, build 74b1e89
省略sudo
将docker加入当前用户组,可以省略每次执行docker指令时,加上sudo
$ sudo groupadd docker
$ sudo gpasswd -a ${USER} docker
$ sudo systemctl restart docker
重启shell
$ docker ps -a # 不再需要加sudo
更换源
$ touch /etc/docker/daemon.json
将以下内容粘贴到新建的 daemon.json
文件中:
{
"registry-mirrors": ["https://ispjh7e6.mirror.aliyuncs.com"]
}
安装 docker-compose
$ sudo curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose
$ sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
查看版本
$ docker-compose -v
docker-compose version 1.24.1, build 4667896b