一、主机规划
[root@localhost ~]# hostnamectl set-hostname AnalysisHost1 192.168.9.188|198.9.6.188
[root@localhost ~]# hostnamectl set-hostname AnalysisHost2 192.168.9.189|198.9.6.189
二、安装docker环境hostnamectl --static set-hostname jetsen-detail-04
如果服务器上面安装过老版本的docker服务那么需要卸载否则不能安装
[root@localhost ~]#
yum remove docker docker-common docker-selinux docker-engine docker-ce
[root@localhost ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
[root@localhost ~]#
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
[root@localhost ~]# yum makecache fast
[root@localhost ~]# yum install docker-ce (安装最新版本的docker)
将版本从大到小排列出来
[root@localhost ~]# yum list docker-ce --showduplicates | sort -r
[root@localhost ~]# yum -y install docker-ce-17.06.1.ce (安装指定版本号的docker)
[root@localhost ~]# docker –v
Docker version 17.09.1-ce, build 19e2cf6
三、docker image 配置
1. 修改 AnalysisHost1(192.168.9.188|198.9.6.188)docker 的配置文件
[root@localhost ~]# 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
[root@localhost ~]# systemctl stop docker(注释:初始化时不会有以下警告,当有image时必出如下警告)
Warning: docker.service changed on disk. Run 'systemctl daemon-reload' to reload units.
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl stop docker(注释:是否需要这一步还不太确定)
[root@localhost ~]# systemctl start docker
设置docker开机启动
[root@localhost ~]# systemctl enable docker
2. 下载centos 镜像
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
[root@localhost ~]# 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. 查看镜像
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 3fa822599e10 3 weeks ago 204MB
4. 删除镜像命令
[root@localhost ~]# docker rmi -f 3fa822599e10
5. 创建共享目录
[root@localhost ~]# mkdir -p /srv/jetsen/test1
6. 启动下载后的镜像(非集群状态启动)
[root@localhost ~]# 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. 查看启动状态
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
abcf8fee7926 centos:latest "/bin/bash" 38 seconds ago Up 37 seconds
8. 停止docker 容器
[root@localhost ~]# docker stop abcf8fee7926
abcf8fee7926
9. 启动docker容器
[root@localhost ~]# docker start abcf8fee7926
abcf8fee7926
10 删除docker容器
[root@localhost ~]# docker rm abcf8fee7926
abcf8fee7926
11 查看所有的容器
[root@localhost ~]# docker ps -a
12 查看对应容器的日志
docker logs -f 81a8a6bb351a
[root@jetsen-detail-03 ~]# docker logs -f --tail 100 42d77b211f30
12 删除所有Exited状态的容器
docker rm $(docker ps -qf status=exited)