CentOS 7(使用 yum 进行安装)
#step 1: 安装必要的一些系统工具
sudo yum install -y yum-utils device-mapper-persistent-data lvm2# Step 2: 添加软件源信息
sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo# Step 3: 更新并安装Docker-CE
sudo yum makecache fast
sudo yum -y install docker-ce# Step 4: 开启Docker服务
sudo systemctl start docker
(下面为加速器)
####查看版本信息
docker --version
###创建docker配置目录
mkdir -p /etc/docker
###重载一下daemon(为了让他读到配置
cd /etc/docker
###上传加速包(daemon.json)
[root@ c7-41 docker]# rz
[root@ c7-41 docker]# ls
daemon.json key.json
###重载一下daemon(为了让他读到配置)
systemctl daemon-reload
###重载一下docker服务
systemctl restart docker
安装bash-completion
yum -y install bash-completion
安装完退出在重新进一下
使用(为镜像的名字)
docker push [ImageID] [repertory_address]提交镜像到云仓库
[root@ c7-41 sbin]# rz
[root@ c7-41 sbin]# ls
docker-compose
[root@ c7-41 sbin]# chmod +x docker-compose
[root@ c7-41 sbin]# ls
docker-compose
#### 查看版本信息
[root@ c7-41 sbin]# docker-compose --version
docker-compose version 1.24.0, build 0aa59064
修改文件
[root@ c7-41 ~]# mkdir nginx
[root@ c7-41 ~]# cd nginx/
[root@ c7-41 nginx]# vim nginx.yml
[root@ c7-41 nginx]# cat nginx.yml
version: "3"
services:
web1:
image: nginx
ports:
- "81:80"
web2:
image: nginx
ports:
- "82:80"
执行
[root@ c7-41 nginx]# docker-compose -f nginx.yml up -d
Creating network "nginx_default" with the default driver
Pulling web1 (nginx:)...
latest: Pulling from library/nginx
54fec2fa59d0: Pull complete
4ede6f09aefe: Pull complete
f9dc69acb465: Pull complete
Digest: sha256:86ae264c3f4acb99b2dee4d0098c40cb8c46dcf9e1148f05d3a51c4df6758c12
Status: Downloaded newer image for nginx:latest
Creating nginx_web1_1 ... done
Creating nginx_web2_1 ... done
[root@ c7-41 nginx]# docker-compose -f nginx.yml ps
Name Command State Ports
----------------------------------------------------------------
nginx_web1_1 nginx -g daemon off; Up 0.0.0.0:81->80/tcp
nginx_web2_1 nginx -g daemon off; Up 0.0.0.0:82->80/tcp