一 、CentOS Docker Swarm集群搭建-环境搭建
一、主机规划
[[email protected] ~]# hostnamectl set-hostname AnalysisHost1 192.168.9.188|198.9.6.188
[[email protected] ~]# hostnamectl set-hostname AnalysisHost2 192.168.9.189|198.9.6.189
二、安装docker环境hostnamectl --static set-hostname jetsen-detail-04
如果服务器上面安装过老版本的docker服务那么需要卸载否则不能安装
[[email protected] ~]#
yum remove docker docker-common docker-selinux docker-engine docker-ce
[[email protected] ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
[[email protected] ~]#
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
[[email protected] ~]# yum makecache fast
[[email protected] ~]# yum install docker-ce (安装最新版本的docker)
将版本从大到小排列出来
[[email protected] ~]# yum list docker-ce --showduplicates | sort -r
[[email protected] ~]# yum -y install docker-ce-17.06.1.ce (安装指定版本号的docker)
[[email protected] ~]# docker –v
Docker version 17.09.1-ce, build 19e2cf6
三、docker image 配置
1. 修改 AnalysisHost1(192.168.9.188|198.9.6.188)docker 的配置文件
[[email protected] ~]# vi /usr/lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd --label=function=jetsen --label=host=analysishost1 --registry-mirror=http://aad0405c.m.daocloud.io
--label=function
指定docker标签,docker compose。Yml文件中会引用,来确定容器的生成位置
--label=host=
指定宿主机的主机名
--registry-mirror=
指定国内私有镜像仓库
修改完成之后,重启docker
[[email protected] ~]# systemctl stop docker(注释:初始化时不会有以下警告,当有image时必出如下警告)
Warning: docker.service changed on disk. Run 'systemctl daemon-reload' to reload units.
[[email protected] ~]# systemctl daemon-reload
[[email protected] ~]# systemctl stop docker(注释:是否需要这一步还不太确定)
[[email protected] ~]# systemctl start docker
设置docker开机启动
[[email protected] ~]# systemctl enable docker
2. 下载centos 镜像
[[email protected] ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
[[email protected] ~]# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
85432449fd0f: Pull complete
Digest: sha256:3b1a65e9a05f0a77b5e8a698d3359459904c2a354dc3b25ae2e2f5c95f0b3667
Status: Downloaded newer image for centos:latest
3. 查看镜像
[[email protected] ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 3fa822599e10 3 weeks ago 204MB
4. 删除镜像命令
[[email protected] ~]# docker rmi -f 3fa822599e10
5. 创建共享目录
[[email protected] ~]# mkdir -p /srv/jetsen/test1
6. 启动下载后的镜像(非集群状态启动)
[[email protected] ~]# docker run -dit --name test1 -v /srv/jetsen/test1:/test1 centos:latest
abcf8fee7926ccac04aadf2b816053e215268b8728519dddcb91c6d15f1f72b5
启动指定端口的容器
docker run -dit --name test1 -v /srv/jetsen/test1:/test1 -p 8080:8080 centos:latest
7. 查看启动状态
[[email protected] ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
abcf8fee7926 centos:latest "/bin/bash" 38 seconds ago Up 37 seconds
8. 停止docker 容器
[[email protected] ~]# docker stop abcf8fee7926
abcf8fee7926
9. 启动docker容器
[[email protected] ~]# docker start abcf8fee7926
abcf8fee7926
10 删除docker容器
[[email protected] ~]# docker rm abcf8fee7926
abcf8fee7926
11 查看所有的容器
[[email protected] ~]# docker ps -a
12 查看对应容器的日志
docker logs -f 81a8a6bb351a
[[email protected] ~]# docker logs -f --tail 100 42d77b211f30
12 删除所有Exited状态的容器
docker rm $(docker ps -qf status=exited)