1.查看ip,命令 ip addr
2.使用Xshell连接,开始安装docker (配置Xshell的 鼠标选中即复制,右键即粘贴)
(1)检查内核版本,必须3.10及以上
uname -r
(2)确保yum是最新的
yum -y update
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
(3)设置阿里云镜像源
sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
如果提示sudo: yum-config-manager:找不到命令,需要执行 yum -y install yum-utils
(4)安装 Docker-CE
sudo yum install -y docker-ce docker-ce-cli containerd.io
安装成功
(5)查看docker版本
docker version
(*)启动docker,命令systemctl start docker
如果启动的时候出现以下错误
Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.
执行:systemctl status docker.service 查看详细的错误信息
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Thu 2018-10-25 09:18:32 CST; 24s ago
Docs: http://docs.docker.com
Process: 12137 ExecStart=/usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=docker-runc --exec-opt native.cgroupdriver=systemd --userland-proxy-path=/usr/libexec/docker/docker-proxy-current --init-path=/usr/libexec/docker/docker-init-current --seccomp-profile=/etc/docker/seccomp.json $OPTIONS $DOCKER_STORAGE_OPTIONS $DOCKER_NETWORK_OPTIONS $ADD_REGISTRY $BLOCK_REGISTRY $INSECURE_REGISTRY $REGISTRIES (code=exited, status=1/FAILURE)
Main PID: 12137 (code=exited, status=1/FAILURE)
Oct 25 09:18:31 localhost.localdomain systemd[1]: Starting Docker Application Container Engine...
Oct 25 09:18:31 localhost.localdomain dockerd-current[12137]: time="2018-10-25T09:18:31.425321071+08:00" level=warning msg="could not change group /var/run/docker.sock to docker: group docker not found"
Oct 25 09:18:31 localhost.localdomain dockerd-current[12137]: time="2018-10-25T09:18:31.442651147+08:00" level=info msg="libcontainerd: new containerd process, pid: 12149"
Oct 25 09:18:32 localhost.localdomain dockerd-current[12137]: time="2018-10-25T09:18:32.466837796+08:00" level=warning msg="overlay2: the backing xfs filesystem is formatted without d_type support, which leads to incorrect behavior. Reformat the filesystem with ftype...
Oct 25 09:18:32 localhost.localdomain dockerd-current[12137]: Error starting daemon: SELinux is not supported with the overlay2 graph driver on this kernel. Either boot into a newer kernel or disable selinux in docker (--selinux-enabled=false)
Oct 25 09:18:32 localhost.localdomain systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE
Oct 25 09:18:32 localhost.localdomain systemd[1]: Failed to start Docker Application Container Engine.
Oct 25 09:18:32 localhost.localdomain systemd[1]: Unit docker.service entered failed state.
Oct 25 09:18:32 localhost.localdomain systemd[1]: docker.service failed.
Hint: Some lines were ellipsized, use -l to show in full.
具体原因是:是由于docker不支持图像内核驱动,SELinux不支持这个内核上的OrthALA2图形驱动程序
解决方式:修改docker配置文件:vi /etc/sysconfig/docker
把OPTIONS一行改为:OPTIONS='--selinux-enabled=false --log-driver=journald --signature-verification=false'
再启动:systemctl start docker 就可以了
(6)设置docker开机启动,systemctl enable docker
(7)停止docker, systemctl stop docker
ps:删除 Docker
sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
删除 docker 相关目录文件(安装docker 后在 /var/lib/docker 目录下包含 images,containers, volumes和自定义的配置文件,这些文件必须手动删除。)
$ sudo rm -rf /var/lib/docker
(8)镜像加速配置
进入阿里云镜像加速页面https://cr.console.aliyun.com/#/accelerator
进入cd /etc/docker (没有则sudo mkdir -p /etc/docker)
将上面的加速器地址替换到下面地址中
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://7lr4t6cd.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
重启服务
sudo systemctl daemon-reload
sudo systemctl restart docker
# systemctl status docker
# systemctl start docker 启动docker
# docker -v 查看版本
# systemctl enable docker 开机启动
docker logs -f --tail=30 logstashmysql 查看日志
[root@localhost docker]# docker -v
Docker version 17.05.0-ce, build 89658be
[root@localhost docker]# systemctl start docker
[root@localhost docker]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
# systemctl stop docker 停止docker
# docker search mysql 搜索镜像
# docker pull mysql 下载镜像
# docker images 查看所有镜像
# docker rmi 67238b4c1da0 删除镜像
拉取镜像地址修改为国内镜像地址
# docker run --name mytomcat -d tomcat:latest 启动容器
# docker ps 查看运行中的容器
# docker ps -a 查看所有容器,包括已停止的
# docker rm cadddabe4267 删除容器
# docker run -d -p 8080:8080 tomcat
# docker run -it --rm tomcat:7-jre7 bash 以交互的方式启动,退出后删除容器
[root@localhost docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat latest 6759d91a032b 4 weeks ago 463MB
mysql latest 2dd01afbe8df 6 weeks ago 485MB
[root@localhost docker]# docker run -d -p 8080:8080 tomcat
启动一个做了端口映射的tomcat,可以在外部访问 -d:后台运行 -p:将主机的端口映射到容器的一个端口
# docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql
(设置中国时区,挂载数据卷)
docker run -d -p 3306:3306 -v /usr/local/docker/mysql/conf:/etc/mysql -v /usr/local/docker/mysql/logs:/var/log/mysql -v /usr/local/docker/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 --name=mysql -e TZ=Asia/Shanghai --restart=always mysql:5.7
[root@localhost docker]# docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql
8d8e6b134216a650bbd216658fc01f593348ff2972013b6ffb6a8e7fa4560264
[root@localhost docker]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8d8e6b134216 mysql "docker-entrypoint..." 7 seconds ago Up 6 seconds 0.0.0.0:3306->3306/tcp, 33060/tcp sleepy_hypatia
50154f09fd33 tomcat "catalina.sh run" 15 minutes ago Up 15 minutes 0.0.0.0:8080->8080/tcp elated_gates
[root@localhost docker]#
在使用docker run启动容器时,使用--restart参数来设置:
--restart具体参数值详细信息:
no - 容器退出时,不重启容器;
on-failure - 只有在非0状态退出时才从新启动容器;
always - 无论退出状态是如何,都重启容器;
docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 --name=mysql -e TZ=Asia/Shanghai --restart=always mysql:5.7
docker run --name redis --restart=always -p 6379:6379 -d redis redis-server --appendonly yes
docker run --name rabbitmq --restart=always -d -p 5671:5671 -p 5672:5672 -p 4369:4369 -p 15671:15671 -p 15672:15672 -p 25672:25672 rabbitmq:management
如果容器已经被创建,我们想要修改容器的重启策略
docker update --restart=always mysql
docker pull 镜像加速
$ docker pull registry.docker-cn.com/library/xxx
elasticsearch启动,限制内存启动
# docker run --name=elasticsearch -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9200:9200 -p 9300:9300 elasticsearch:5.6.8
以配置文件挂载的方式启动elasticsearch(前提elasticsearch容器必须启动着)
先复制出一份配置文件
docker cp elasticsearch:/usr/share/elasticsearch/config/elasticsearch.yml /usr/share/elasticsearch.yml
修改配置文件 [root@jiangli ~]# vi /usr/share/elasticsearch.yml ,打开这一行的注释
修改宿主机的配置 vi /etc/security/limits.conf ,在最后加
* soft nofile 65536
* hard nofile 65536
修改 vi /etc/sysctl.conf ,最后添加
vm.max_map_count=655360
reboot后挂载启动
docker run --name=elasticsearch -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9200:9200 -p 9300:9300 -v /usr/share/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml elasticsearch:5.6.8
添加ik分词器后测试
http://192.168.136.130:9200/_analyze?analyzer=ik_smart&pretty=true&text=我的程序员
安装elasticsearch-header插件
先设置运行跨域 vi /usr/share/elasticsearch.yml 添加
http.cors.enabled: true
http.cors.allow-origin: "*"
然后restart elasticsearch
再启动header
docker run -d --name=elasticsearch-header -p 9100:9100 mobz/elasticsearch-head:5
OK!!!
启动mongo
docker run -d --name=mongo -p 27017:27017 mongo
进入mongo容器
docker exec -it mongo /bin/bash
创建数据库
[root@jiangli ~]# docker exec -it mongo /bin/bash
root@cd72e4c31070:/# mongo
> use spitdb
docker启动tomcat(前提将项目放入数据卷的ROOT目录中)
docker run -p 8080:8080 --name mytom -v /usr/local/docker/tomcat/ROOT/:/usr/local/tomcat/webapps/ROOT -d tomcat