[root@localhost ~]# sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的
[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 list docker-ce --showduplicates | sort -r
[root@localhost ~]# sudo yum install docker-ce docker-ce-cli containerd.io
# 1.启动
[root@localhost ~]# systemctl start docker
# 2.开机自启
[root@localhost ~]# systemctl enable docker
[root@localhost ~]# docker version
[root@localhost ~]# yum erase 安装包
[root@localhost ~]# docker pull mysql:5.7
# 1.查看镜像
[root@localhost ~]# docker images
# 2.启动mysql镜像
[root@localhost ~]# docker run -p 3306:3306 --name mysql \
-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 \
-d mysql:5.7;
选项 | 说明 |
---|---|
-p | 端口映射,此处映射 主机3306端口 到 容器的3306端口 |
–name | 容器名,此处命名为mysql |
-e | 配置信息,此处配置mysql的root用户的登陆密码 |
-v | 主机和容器的目录映射关系,":"前为主机目录,之后为容器目录 |
[root@localhost ~]# docker ps
# 开放端口:
[root@localhost ~]# systemctl status firewalld
[root@localhost ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
[root@localhost ~]# firewall-cmd --reload
# 关闭防火墙:
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# docker exec -it mysql bash
root@0a395d1f0340:/# mysql -uroot -p
# 设置
mysql> grant all privileges on *.* to root@'%' identified by "aptx4869";
# 刷新
mysql> flush privileges;
# 查看
mysql>
mysql> select host,user from user;
+-----------+---------------+
| host | user |
+-----------+---------------+
| % | root |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+---------------+
# 1.查看字符编码
mysql> show variables like'character%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
# 2.修改字符编码
mysql> set names 'utf8';
mysql> set character_set_seexitrver=utf8;
mysql> show variables like'character%';
# 或者在/usr/local/docker/mysql/conf目录下新建my.cnf文件,并添加以下内容
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
skip-name-resolve
[root@localhost ~]# docker pull redis:5.0.11
[root@localhost ~]# docker images
# 新建目录
[root@localhost ~]# mkdir -p /usr/local/docker/redis/conf/
# 新建文件
[root@localhost ~]# touch /usr/local/docker/redis/conf/redis.conf
[root@localhost ~]# docker run -p 6379:6379 --name redis \
-v /usr/local/docker/redis/conf/redis.conf:/etc/redis/redis.conf \
-v /usr/local/docker/redis/data:/data \
-d redis:latest redis-server /etc/redis/redis.conf \
--appendonly yes;
- -p 6379:6379:把容器内的6379端口映射到宿主机6379端口
- -v /root/docker/redis/redis.conf:/etc/redis/redis.conf:
- 把宿主机配置好的redis.conf放到容器内的这个位置中
- -v /root/docker/redis/data:/data:
- 把redis持久化的数据在宿主机内显示,做数据备份
- redis-server /etc/redis/redis.conf:
- 这个是关键配置,让redis不是无配置启动,而是按照这个redis.conf的配置启动
- -appendonly yes:redis启动后数据持久化
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ad665e9657b9 redis:5.0.11 "docker-entrypoint.s…" 37 seconds ago Up 27 seconds 0.0.0.0:6379->6379/tcp, :::6379->6379/tcp redis
0a395d1f0340 mysql:5.7 "docker-entrypoint.s…" 56 minutes ago Up 56 minutes 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp mysql
# mysql
docker update mysql --restart=always
# redis
docker update redis --restart=always
# 存储和检索数据
docker pull elasticsearch:7.4.2
# 可视化检索数据
docker pull kibana:7.4.2
# 创建配置文件目录,数据目录
mkdir -p /usr/local/docker/elasticsearch/{conf,data}
# 将/usr/local/docker/elasticsearch/文件夹中文件都可读可写
chmod -R 777 /usr/local/docker/elasticsearch/
# 配置任意机器可以访问 elasticsearch
echo "http.host: 0.0.0.0" > /usr/local/docker/elasticsearch/config/elasticsearch.yml
docker run --name elasticsearch -p 9200:9200 -p 9300:9300 \
-e "discovery.type=single-node" \
-e ES_JAVA_OPTS="-Xms64m -Xmx512m" \
-v /usr/local/docker/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v /usr/local/docker/elasticsearch/data:/usr/share/elasticsearch/data \
-v /usr/local/docker/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
-d elasticsearch:7.4.2
-p 9200:9200 -p 9300:9300
:向外暴露两个端口,9200用于HTTP REST API请求,9300 ES 在分布式集群状态下 ES 之间的通信端口;
-e "discovery.type=single-node"
:es 以单节点运行
-e ES_JAVA_OPTS="-Xms64m -Xmx512m"
:设置启动占用内存,不设置可能会占用当前系统所有内存-v:挂载容器中的配置文件、数据文件、插件数据到本机的文件夹;
-d elasticsearch:7.6.2
:指定要启动的镜像访问 IP:9200 看到返回的 json 数据说明启动成功。
# 当前 Docker 开机自启,所以 ES 现在也是开机自启
docker update elasticsearch --restart=always
docker run --name kibana \
-e ELASTICSEARCH_HOSTS=http://192.168.21.150:9200 \
-p 5601:5601 \
-d kibana:7.4.2
-e ELASTICSEARCH_HOSTS=``http://192.168.163.131:9200
: 这里要设置成自己的虚拟机IP地址浏览器输入192.168.21.150:5601 测试
# 当前 Docker 开机自启,所以 kibana 现在也是开机自启
docker update kibana --restart=always
# 1. 拉取镜像
[root@localhost ~]# docker pull nacos/nacos-server:1.2.1
# 2. 新建目录
[root@localhost ~]# mkdir -p /home/nacos/logs/
# 3. 启动nacos
docker run --name nacos -d -p 8848:8848 --privileged=true \
--restart=always \
-e JVM_XMS=512m \
-e JVM_XMX=2048m \
-e MODE=standalone \
-e PREFER_HOST_MODE=hostname \
-v /home/nacos/logs:/home/nacos/logs \
nacos/nacos-server:1.2.1
[root@localhost ~]# nohup java -jar est.jar >debug.log 2>&1 &
[root@localhost ~]# tail -f debug.log
# 8080端口
[root@localhost ~]# firewall-cmd --zone=public --add-port=8080/tcp --permanent
success
[root@localhost ~]# firewall-cmd --reload
success
docker run --name nginx \
-d -p 80:80 \
-v /usr/local/docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /usr/local/docker/nginx/log:/var/log/nginx \
-v /usr/local/docker/nginx/html:/usr/share/nginx/html \
-v /usr/local/estHtml/:/usr/local/estHtml \
-d nginx:1.16.1;
WARNING: IPv4 forwarding is disabled. Networking will not work.
# 第一步:在宿主机上执行
[root@localhost /]# echo "net.ipv4.ip_forward=1" >>/usr/lib/sysctl.d/00-system.conf
[root@localhost /]# systemctl restart network && systemctl restart docker