docker及docker-compose安装
基于操作系统centos 7,官方安装文档
- 删除旧版本
$ sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine
- 安装仓库(Install using the repository)
# step 1: 安装必要的一些系统工具
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
# Step 2: 添加软件源信息
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# Step 3: 更新并安装 Docker-CE
sudo yum makecache fast
sudo yum -y install docker-ce
#开机启动
systemctl enable docker.service
systemctl start docker
- 查看docker版本
yum list docker-ce --showduplicates | sort -r
- 安装Docker引擎(INSTALL DOCKER ENGINE - COMMUNITY)
$ sudo yum install docker-ce docker-ce-cli containerd.io
- 验证是否安装成功
$ sudo docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
Docker启动|停止|状态查看
#启动
$ sudo systemctl start docker
#停止
$ sudo systemctl stop docker
#重启
$ sudo systemctl restart docker
#运行状态查看
$ sudo systemctl status docker
6.开启2375端口
1.修改启动配置
$ vim /usr/lib/systemd/system/docker.service
#找到ExecStart开始的行,增加-H tcp://0.0.0.0:2375
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
2.使配置生效
$ systemctl daemon-reload
3.重启docker
$ systemctl restart docker
4.查看端口是否暴露
$ netstat -tlnp
7.docker-compose安装(仅一个二进行程序包)
1.下载docker-compose
sudo curl -L "https://github.com/docker/compose/releases/download/1.25.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
2.授权
sudo chmod +x /usr/local/bin/docker-compose