docker 买了腾讯服务器后的学习
騰訊云買了? ?打算用?
?
登錄成功后:
Last login: Mon Nov 11 13:37:02 2019 from 221.12.17.87
[root@VM_0_13_centos ~]# ip addr ? ? ? ? ?#查看ip地址
[root@VM_0_13_centos ~]# uname -r ?#查看centeros內核版本? docker要求 ?centeros內核在3.10以上
3.10.0-862.el7.x86_64
[root@VM_0_13_centos ~]# yum install docker ? ? ? ? #聯網安裝docker ?中間有一次輸入y要下載東西
[root@VM_0_13_centos ~]# systemctl start docker ? ? #啟動docker
[root@VM_0_13_centos ~]# docker -v ? ? ?#查看docker版本
Docker version 1.13.1, build 7f2769b/1.13.1
[root@VM_0_13_centos ~]# systemctl enable docker ? ? #設置docker開機啟動
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.ser
vice.
[root@VM_0_13_centos ~]# systemctl stop docker ? #也可以停止docker
[root@VM_0_13_centos ~]# docker -v ? ?#查看docker版本
Docker version 1.13.1, build 7f2769b/1.13.1
[root@VM_0_13_centos ~]# docker search mysql ?#在線搜索docker的mysql鏡像 ?這個沒什么用
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? #剛才關閉了docker
[root@VM_0_13_centos ~]# systemctl start docker ? # 剛才關閉了docker? ? 啟動docker
[root@VM_0_13_centos ~]# clear? ? #清理界面
https://hub.docker.com/? ? ?這里可以找docker鏡像的版本
[root@VM_0_13_centos ~]# docker search mysql? #查找mysql鏡像
[root@VM_0_13_centos ~]# docker pull mysql? ?#拉取最新的mysql鏡像??? latest最新版本的鏡像? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
[root@VM_0_13_centos ~]# docker images? #查看當前下載好的鏡像
[root@VM_0_13_centos ~]# docker pull mysql:5.5? ?#拉取mysql5.5的鏡像??
[root@VM_0_13_centos ~]# docker rmi d404d78aa797? ? #刪除指定id的鏡像
[root@VM_0_13_centos ~]# docker images d404d78aa797? ?#沒有用的命令。壓根就沒這個命令
?[root@VM_0_13_centos ~]# docker ps? ? ? ? ? ? ? ? ? ? ? #查看運行中的鏡像
[root@VM_0_13_centos ~]# docker search tomcat? ? ? ? ?#搜索tomcat鏡像
[root@VM_0_13_centos ~]# docker pull tomcat? ? ? ? #拉取tomcat的鏡像
[root@VM_0_13_centos ~]# docker images? ? ? ? ? ? ? #查看現有鏡像
[root@VM_0_13_centos ~]# docker ps? ? ? ? ? ? ? ? ? ? ? #查看運行中的鏡像
?
?
[root@VM_0_13_centos ~]# docker images ? ?#下載好的鏡像
[root@VM_0_13_centos ~]# docker ps ? ?#運行中的鏡像
[root@VM_0_13_centos ~]# docker run --name mytomcat2 -d tomcat? 不能用? #運行鏡像 (忘記映射端口了 ?這個不能用)
[root@VM_0_13_centos ~]# docker ps ?#運行中的鏡像
[root@VM_0_13_centos ~]# docker stop 0d9f1656799c ? ?#停止運行中的鏡像
[root@VM_0_13_centos ~]# docker ps ? #運行中的鏡像
[root@VM_0_13_centos ~]# docker stop 16d6eadacf1e ? #停止運行中的鏡像
[root@VM_0_13_centos ~]# docker ps ? ?#運行中的鏡像
[root@VM_0_13_centos ~]# docker ps -a ? ?#運行中的鏡像和停止的鏡像
[root@VM_0_13_centos ~]# docker start 0d9f1656799c ? #啟動已經停止的鏡像(容器)
[root@VM_0_13_centos ~]# docker ps ? #運行中的對象
[root@VM_0_13_centos ~]# docker stop 0d9f1656799c ? ? ?#停止運行中的鏡像
[root@VM_0_13_centos ~]# docker ps ?#運行中的鏡像
[root@VM_0_13_centos ~]# docker rm 0d9f1656799c ? #刪除已經停止的鏡像
[root@VM_0_13_centos ~]# docker ps -a ? ?#運行中的鏡像和停止的鏡像
??
?
[root@VM_0_13_centos ~]# docker ps ? ??#運行中的鏡像
[root@VM_0_13_centos ~]# docker stop 0d9f1656799c ? ?#停止運行中的鏡像
[root@VM_0_13_centos ~]# docker ps ? ? ?#運行中的鏡像
[root@VM_0_13_centos ~]# docker stop 16d6eadacf1e ? ?#停止運行中的鏡像
[root@VM_0_13_centos ~]# docker ps ? #運行中的鏡像
[root@VM_0_13_centos ~]# docker ps -a ? ?#運行中的鏡像和停止的鏡像
[root@VM_0_13_centos ~]# docker images ? #下載好的鏡像 ?
[root@VM_0_13_centos ~]# docker run -d -p 8888:8080 tomcat? ? #啟動tomcat
[root@VM_0_13_centos ~]# docker ps ? ?#運行中的鏡像
[root@VM_0_13_centos ~]# docker ps -a? ? #運行中的鏡像和停止的鏡像
[root@VM_0_13_centos ~]# service firewalld status? ? ?#防火墻狀態
? ?Active: inactive (dead) ?
[root@VM_0_13_centos ~]# service firewalld stop? ? ?#停用防火墻(騰訊好像默認是停用的)
[root@VM_0_13_centos ~]# docker logs 2c9f0c97245d ?#日志
[root@VM_0_13_centos ~]# docker run -d -p 8889:8080 tomcat ? ?#啟動tomcat
[root@VM_0_13_centos ~]# docker run -d -p 8887:8080 tomcat ? ?#一個鏡像可以啟動多個tomcat
[root@VM_0_13_centos ~]# docker ps ?#運行中的鏡像(容器)
?
?
[root@VM_0_13_centos ~]# docker ps ? ? #查看運行中的鏡像
[root@VM_0_13_centos ~]# docker stop abefecfa6a61 ? #停止運行中的鏡像(指定id)
[root@VM_0_13_centos ~]# docker ps ? ?#查看運行中的鏡像
[root@VM_0_13_centos ~]# docker images ? ?#查看已下載的鏡像
[root@VM_0_13_centos ~]# docker run -p 3306:3306 --name mysql02 -e MYSQL_ROOT_PASSWORD=123456 -d mysql ?#啟動mysql(沒有自定字符集)
[root@VM_0_13_centos ~]# docker stop a08a88b2ea42 ? #停止運行中的鏡像(指定id)
[root@VM_0_13_centos ~]# docker ps -a ? #查看所有運行和停止的鏡像
[root@VM_0_13_centos ~]# docker rm a08a88b2ea42 ? #刪除已經停止的鏡像
[root@VM_0_13_centos ~]# docker rm 281a9b9f9fd5 ?#這個命令可以刪除鏡像也可以刪除停止運行的鏡像,運行中的必須停止后刪除
#不同版本的mysql 可以同時啟動? ? 但是端口要不一樣
[root@VM_0_13_centos ~]# docker run -p 3306:3306 --name mysql5.5 -e MYSQL_ROOT_PASSWORD=123456 -d mysql --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci? ?#啟動mysql 并指定字符集
[root@VM_0_13_centos ~]# docker run -p 3306:3306 --name mysql5.5 -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.5 -
-character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci??#啟動mysql 并指定字符集3306端口? 鏡像mysql5.5
[root@VM_0_13_centos ~]# docker run -p 3307:3306 --name mysql_latest -e MYSQL_ROOT_PASSWORD=123456 -d mysql:l
atest --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci??#啟動mysql 并指定字符集3307端口鏡mysqllatest
?
上面是? ?第5章SpringBoot_Docker? ? 全部看完了? 挺好用的。
?
?
下面是? ?第6章SpringBoot數據訪問
[root@VM_0_13_centos ~]# docker ps -a ? #查看已經停止和正在運行的鏡像(容器)
[root@VM_0_13_centos ~]# docker start abefecfa6a61 ? #啟動已經聽通知的鏡像(容器)
abefecfa6a61
[root@VM_0_13_centos ~]# docker ps ? #查看正在運行的鏡像(容器)
[root@VM_0_13_centos ~]# docker stop abefecfa6a61 ? #停止正在運行的鏡像(容器)
?
?
?
第7章SpringBoot原理
這節沒用docker
?
?
?
?第8章SpringBoot緩存
[root@VM_0_13_centos ~]# docker images? ?#查看下載好的鏡像
[root@VM_0_13_centos ~]# docker ps? ? ?#正在運行的鏡像(容器)
[root@VM_0_13_centos ~]# docker ps -a? ? #正在運行和已經停止的鏡像(容器)
[root@VM_0_13_centos ~]# docker rm 13f20f7c86ae? ?#刪除已經停止的鏡像(容器)
13f20f7c86ae
[root@VM_0_13_centos ~]# docker rm a30fa73f63f5? ? ??#刪除已經停止的鏡像(容器)
a30fa73f63f5
[root@VM_0_13_centos ~]# docker rmi 752be83a5396? ??#刪除已經下載好的鏡像
[root@VM_0_13_centos ~]# docker images? ??#查看下載好的鏡像
[root@VM_0_13_centos ~]# docker pull redis? ? #拉取redis鏡像
[root@VM_0_13_centos ~]# docker run -d -p 6379:6379 --name myredis redis? ? #啟動redis鏡像并做端口映射
?
?
?
第9章SpringBoot消息
[root@VM_0_13_centos ~]# docker pull rabbitmq:3-management ? #拉取rabittmq鏡像
[root@VM_0_13_?~]# docker run -d -p 5672:5672 -p 15672:15672 --name myrabbitmq 5ab234e119da ?#運行rabbitmq鏡像
[root@VM_0_13_centos ~]# docker rmi 36ed80b6a1b1 ? 刪除鏡像
[root@VM_0_13_centos ~]# docker images ? 已經下載好的鏡像
[root@VM_0_13_centos ~]# docker rmi 5ab234e119da ? 刪除鏡像
[root@VM_0_13_centos ~]# docker stop dd491afb90ae ?停止運行中的容器
[root@VM_0_13_centos ~]# docker rm dd491afb90ae ?刪除容器
[root@VM_0_13_centos ~]# docker ps -a ? 查看所有容器 停止和運行的都顯示
[root@VM_0_13_centos ~]# docker pull rabbitmq:3-management ? ?下載帶管理界面的rabbitmq
[root@VM_0_13_centos ~]# docker images ? ?查看下載好的鏡像
[root@VM_0_13_centos ~]# docker run -d -p 5672:5672 -p 15672:15672 --name myrabbitmq 36ed80b6a1b1 ? ?啟動rabbitMq
[root@VM_0_13_centos ~]# docker ps ? ?查看正在運行的容器
?
?
第10章SpringBoot檢索
$ ?docker ?pull ?openjdk? ?#elasticearch需要java環境
$ docker ?run ?-d ?-it ?--name myopenjdk ?openjdk ?/bin/bash? ?啟動java環境
[root@VM_0_13_centos ~]# docker stop dcdf2364fb88 ?停止容器
[root@VM_0_13_centos ~]# docker rm 1bed98e3bf77 ?刪除容器
[root@VM_0_13_centos ~]# docker search elasticsearch ? 搜索鏡像(這個命令沒什么用)
[root@VM_0_13_centos ~]# docker pull elasticsearch:5.6.9 ? 下載elasticsearch:5.6.9鏡像
#啟動elasticsearch:5.6.9 ?
[root@VM_0_13_centos ~]#
docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9200:9200 -p 9300:9300 --name elasticsearch01 5c1e1ecfe33a
[root@VM_0_13_centos ~]# docker rmi 5e9d896dc62c ?刪除鏡像
[root@VM_0_13_centos ~]# docker pull elasticsearch:2.4.6 ? 下載elasticsearch:2.4.6
[root@VM_0_13_centos ~]# docker images ?查看鏡像下載好的
#啟動elasticsearch:2.4.6 ?
[root@VM_0_13_centos ~]#
docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9201:9200 -p 9301:9300 --name elasticsearch02 5e9d896dc62c
[root@VM_0_13_centos ~]# docker ps -a ? ?查看所有容器停止的和沒有停止的
[root@VM_0_13_centos ~]# docker start 9bb596831d2d ? ?啟動容器
[root@VM_0_13_centos ~]# docker ps ? ?查看正在運行的容器
?
?
第11章SpringBoot任務
這個沒有docker命令
?
?
?
第12章SpringBoot安全
這章也沒有docker
?
?
第13章SpringBoot分布式
docker images? 查看下載好的鏡像
docker pull zookeeper:3.4.11? ? 下載zookeeper
docker run --name zookeeper01 -p 2181:2181 --restart always -d? ? xxxxxxxid? ?啟動zookeeper
docker ps
?
[root@VM_0_13_centos ~]# docker ps -a ? 查看容器包括運行和停止的
[root@VM_0_13_centos ~]# docker stop 27bef5f236d3 ? 停止運行中的容器
[root@VM_0_13_centos ~]# docker rm 27bef5f236d3 ? 刪除容器
[root@VM_0_13_centos ~]# docker rmi 56d414270ae3 ?刪除鏡像
[root@VM_0_13_centos ~]# docker pull zookeeper:3.4.11 ? ?下載zookeeper
[root@VM_0_13_centos ~]# docker images ? 查看下載好的鏡像
[root@VM_0_13_centos ~]# docker run --name zookeeper01 -p 2181:2181 --restart always -d 56d414270ae3 ? ?啟動zookeeper
[root@VM_0_13_centos ~]# docker ps ? 查看運行中的容器
?
?
第14章SpringBoot熱部署
沒有docker命令
?
?
第15章SpringBoot監管
沒有docker命令
?
?
?
百度搜索 dockers hub
1.安裝jdk
$ ?docker ?pull ?openjdk
$ docker ?run ?-d ?-it ?--name myopenjdk ?openjdk ?/bin/bash
2.安裝elasticsearch?
docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9200:9200 -p 9300:9300 --name ES01 5c1e1ecfe33a
? ? ? ?#啟動elasticsearch:5.6.9的鏡像
#??https://hub.docker.com/? ? ?這里可以找docker鏡像的版本
#下面的都做過了看一下就好了
Last login: Tue Nov 12 13:56:07 2019 from 221.12.17.87
[root@VM_0_13_centos ~]# docker search elasticsearch? ?#查找elasticsearch
?
[root@VM_0_13_centos ~]# docker pull elasticsearch:5.6.9? ? #拉這個版本是視頻上的
Get https://registry.docker-cn.com/v1/_ping: dial tcp 106.14.52.175:443: i/o timeout? ?#超時
[root@VM_0_13_centos ~]# docker pull elasticsearch:6.2.1? ?#找不到這個版本
Trying to pull repository docker.io/library/elasticsearch ...?
manifest for docker.io/elasticsearch:6.2.1 not found
[root@VM_0_13_centos ~]# docker pull elasticsearch:6.5.0? ?#這個照著博客上的版本可以了? ?這個版本太高用不了
Status: Downloaded newer image for docker.io/elasticsearch:6.5.0?
[root@VM_0_13_centos ~]# docker images? ?#目前有的鏡像 已經下載好了
REPOSITORY ? ? ? ? ? ? ? ?TAG ? ? ? ? ? ? ? ? IMAGE ID ? ? ? ? ? ?CREATED ? ? ? ? ? ? SIZE
docker.io/elasticsearch ? 6.5.0 ? ? ? ? ? ? ? ff171d17e77c ? ? ? ?12 months ago ? ? ? 774 MB
[root@VM_0_13_centos ~]#
docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9200:9200 -p 9300:9300 --name ES01 5c1e1ecfe33a
? ? ? ?#啟動elasticsearch:5.6.9的鏡像
efc5eac2266b6205c111523b29184554e300ce3ee0261477d7d8175ede004b3c
[root@VM_0_13_centos ~]# docker ps? ?#查看已經啟動的鏡像
CONTAINER ID? ?IMAGE? ?COMMAND? ?CREATED? ? STATUS? ?PORTS? ?NAMES
efc5eac2266b ? ? ? ?ff171d17e77c ? ? ? ?"/usr/local/bin/do..." ? 14 seconds ago ? ? ?Up 14 seconds ? ? ? 0.0.
0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp ? ES01
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
zimuge視頻上的docker命令匯總
第十一章redis緩存? ? ?這是第一次使用到docker
[root@VM_0_13_centos ~]# systemctl status docker? ?查看docker運行狀態
● docker.service - Docker Application Container Engine
? ?Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
? ?Active: active (running) since Mon 2019-11-11 13:46:58 CST; 4 weeks 1 days ago? ?docker正在運行
? ? ?Docs: http://docs.docker.com?
[root@VM_0_13_centos ~]# systemctl restart docker?? ?如果docker沒有啟動 就重啟docker
[root@VM_0_13_centos ~]# docker images? ? 查看有哪些鏡像了
[root@VM_0_13_centos ~]# docker search redis? ? ?查看有哪些redis的版本
[root@VM_0_13_centos ~]# docker pull redis:5.0.5? ? 這是老師找到的比較穩定的版本
如果你不懂的話? 可以暫時把docker理解為一個虛擬機? 但是不一樣的 這是2回事
https://raw.githubusercontent.com/antirez/redis/4.0/redis.conf? ? ?這個配置文件 修改一下redis官方默認的配置文件
剛才做了一下docker restart docker? ?然后docker ps -all 就剩下 zookeeper容器還在了
[root@VM_0_13_centos ~]# docker ps? ?? ? 只有 zookeeper01了
[root@VM_0_13_centos ~]# docker ps -all? ? ?也只有 zookeeper01了
?
注意:后面所有的操作命令都要在這個目錄/home/docker/redis下進行
獲取 redis 的默認配置模版
# 獲取 redis 的默認配置模版 # 這里主要是想設置下 redis 的 log / password / appendonly # redis 的 docker 運行參數提供了 --appendonly yes 但沒 password wget https://raw.githubusercontent.com/antirez/redis/4.0/redis.conf -O conf/redis.conf# 直接替換編輯 sed -i 's/logfile ""/logfile "access.log"/' conf/redis.conf; sed -i 's/# requirepass foobared/requirepass 123456/' conf/redis.conf; sed -i 's/appendonly no/appendonly yes/' conf/redis.conf; sed -i 's/bind 127.0.0.1/bind 0.0.0.0/' conf/redis.conf;[root@VM_0_13_centos redis]# pwd? ? ?linux如何查看當前目錄的完整路徑
/home/docker/redis??
[root@VM_0_13_centos redis]# pwd
/home/docker/redis
[root@VM_0_13_centos redis]# cd conf
[root@VM_0_13_centos conf]# pwd
/home/docker/redis/conf
示例:
? ? 1、刪除文件夾實例:
? ? rm -rf /var/log/httpd
? ? 將會刪除/var/log/httpd目錄以及其下所有文件、文件夾
? ? 2、刪除文件使用實例:
? ? rm -f /var/log/httpd/access.log
? ? 將會強制刪除/var/log/httpd/access.log這個文件
注意:使用 rm -rf 的時候一定要小心,Linux沒有回收站。
創建宿主機 redis 容器的數據和配置文件目錄??
mkdir命令用于建立名稱為 dirName 之子目錄。?-p 確保目錄名稱存在,不存在的就建一個。
[root@VM_0_13_centos redis]# mkdir /home/docker/redis/{conf,data} -p? ? ? 創建這2個目錄/conf/data
[root@VM_0_13_centos redis]# cd /home/docker/redis? ? ?進入目錄
?這個配置文件 修改一下redis官方默認的配置文件
?wget是Linux下下載文件的最常用命令。wget支持HTTP,HTTPS和FTP協議,支持自動下載,即可以在用戶退出系統后在后臺執行,直到下載結束。? ? ? ? -O是大寫的o? 不是數字也不是小寫的o? ? 尼瑪就一直是錯在這里啊啊啊
[root@VM_0_13_centos redis]# wget https://raw.githubusercontent.com/antirez/redis/4.0/redis.conf -O?conf/redis.conf
[root@VM_0_13_centos redis]# cd /home/docker/redis? ? ?進入目錄
[root@VM_0_13_centos redis]# pwd? ? 當前目錄
/home/docker/redis
[root@VM_0_13_centos redis]# ls -ltr? 查看當前目錄的文件? ?以后就在/home/docker/redis文件夾中操作了
total 68
drwxr-xr-x 2 root root ?4096 Dec 10 20:22 data
-rw-r--r-- 1 root root 58766 Dec 10 20:22 redis.conf
drwxr-xr-x 2 root root ?4096 Dec 10 20:23 conf
就是字符串替換? ?下面的代碼
[root@VM_0_13_centos redis]# sed -i 's/logfile ""/logfile "access.log"/' conf/redis.conf;
logfile原來為空字符串的 現在遠程access.log?
[root@VM_0_13_centos redis]# sed -i 's/# requirepass foobared/requirepass 123456/' conf/redis.conf;
原來不用密碼訪問的現在修改為 密碼登錄123456
[root@VM_0_13_centos redis]# sed -i 's/appendonly no/appendonly yes/' conf/redis.conf;
原來持久化為no 現在修改為yes
[root@VM_0_13_centos redis]# sed -i 's/bind 127.0.0.1/bind 0.0.0.0/' conf/redis.conf;
原來只有127.0.0.1才能訪問現在修改為全部ip可以訪問
protected-mode 是在沒有顯式定義 bind 地址(即監聽全網段),又沒有設置密碼 requirepass時,protected-mode 只允許本地回環 127.0.0.1 訪問。改為bind 0.0.0.0
容器相當于類? ? 鏡像相當于對象
?
[root@VM_0_13_centos ~]# pwd? ?查看當前全路徑
[root@VM_0_13_centos ~]# docker search redis? ?搜索redis鏡像?
[root@VM_0_13_centos ~]# docker images? ? ?查詢已經下載好的鏡像
[root@VM_0_13_centos ~]# mkdir /home/docker/redis/{conf,data} -p? ? ?# 這里我們在 /home/docker 下創建
[root@VM_0_13_centos ~]# cd /home/docker/redis? ?打開指定目錄
[root@VM_0_13_centos redis]# pwd? ? 當前全路徑
/home/docker/redis
[root@VM_0_13_centos redis]# ls -a? ?-a 顯示所有文件及目錄 (ls內定將文件名或目錄名稱開頭為"."的視為隱藏檔,不會列出)
conf ?data ?redis.conf
ls 顯示目錄下的文件名
-a 顯示所有文件(包含隱藏文件),以.開頭的文件為隱藏文件
-A 顯示所有文件(不包含.和..)
[root@VM_0_13_centos redis]# docker rm 34b604a489e4? ? ?刪除容器
[root@VM_0_13_centos redis]# docker rmi 63130206b0fa? ? 刪除鏡像
[root@VM_0_13_centos redis]# docker images? ? 不能再redis目錄下面做? 必須cd ~ 回到主目錄才行? 不然報下面這行的錯誤
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
[root@VM_0_13_centos redis]# docker pull redis:5.0.5? ? 拉redis:5.0.5這個鏡像
[root@VM_0_13_centos redis]# cd ..? ?回到上層目錄
[root@VM_0_13_centos /]# cd ~? ? 回到主目錄
[root@VM_0_13_centos redis]# docker logs myredis5? ?沒啟動起來查看日志?# 如果沒有 myredis 說明啟動失敗 查看錯誤日志
[root@VM_0_13_centos redis]# cat conf/redis.conf? ? ? 查看這個redis.conf文件
[root@VM_0_13_centos conf]# vi redis.conf? ?編輯redis.conf這個文件
[root@VM_0_13_centos conf]# docker ps? ? 查看運行的容器? ?# 查看活躍的容器
[root@VM_0_13_centos conf]# docker ps -a? ?查看所有運行和停止運行的容器
[root@VM_0_13_centos redis]# docker stop 8a3ec673e16f? ? 停止運行中的容器
[root@VM_0_13_centos redis]# rm -rf /home/docker/redis? ? ?刪除/home/docker/redis目錄下的所有文件夾和文件
[root@VM_0_13_centos redis]# sed -i 's/logfile ""/logfile "access.log"/' conf/redis.conf;
[root@VM_0_13_centos redis]# sed -i 's/# requirepass foobared/requirepass 123456/' conf/redis.conf;
[root@VM_0_13_centos redis]# sed -i 's/appendonly no/appendonly yes/' conf/redis.conf;
[root@VM_0_13_centos redis]# sed -i 's/bind 127.0.0.1/bind 0.0.0.0/' conf/redis.conf;
[root@VM_0_13_centos redis]# docker run -p 6379:6379 -v $PWD/data:/data:rw -v $PWD/conf/redis.conf:/etc/redis/redis.conf:ro ? --privileged=true --name myredis5 ? -d redis redis-server /etc/redis/redis.conf ??
?啟動redis? ?必須一行寫命令不然就會出錯的
# 命令分解
docker run \
-p 6379:6379 \ # 端口映射 宿主機:容器
-v $PWD/data:/data:rw \ # 映射數據目錄 rw 為讀寫
-v $PWD/conf/redis.conf:/etc/redis/redis.conf:ro \ # 掛載配置文件 ro 為readonly
--privileged=true \ # 給與一些權限
--name myredis \ # 給容器起個名字
-d redis redis-server /etc/redis/redis.conf # deamon 運行容器 并使用配置文件啟動容器內的 redis-server?
[root@VM_0_13_centos redis]# docker logs myredis5? ?啟動失敗就看看日志
[root@VM_0_13_centos redis]# docker inspect myredis5?# 查看 myredis 的 ip 掛載 端口映射等信息
[root@VM_0_13_centos redis]# docker port myredis5??# 查看 myredis 的端口映射
6379/tcp -> 0.0.0.0:6379
[root@VM_0_13_centos redis]# docker exec -it myredis5 bash? ?三、訪問 redis 容器服務
root@26b861b7ec37:/data#?
root@26b861b7ec37:/data# redis-cli
127.0.0.1:6379>?
127.0.0.1:6379> exit? ?退出
?root@26b861b7ec37:/data# exit? ?退出
exit
?[root@VM_0_13_centos ~]#?
四、開啟防火墻端口,提供外部訪問
[root@VM_0_13_centos redis]# firewall-cmd --zone=public --add-port=6379/tcp --permanent
FirewallD is not running
[root@VM_0_13_centos redis]# firewall-cmd -reload
usage: see firewall-cmd man page
firewall-cmd: error: unrecognized arguments: -reload
[root@VM_0_13_centos redis]# firewall-cmd --query-port=6379/tcp
FirewallD is not running
[root@VM_0_13_centos redis]#?
?
[root@VM_0_13_centos ~]# docker logs myredis5? ?看一下redis的日志,這里暫時沒有日志
?
[root@VM_0_13_centos ~]# docker port myredis5? ? ?檢查redis的端口? 6379
6379/tcp -> 0.0.0.0:6379
[root@VM_0_13_centos ~]# docker exec -it myredis5 bash? ? ? 現在是在主機上面,進入redis試試
root@26b861b7ec37:/data#?
root@26b861b7ec37:/data# redis-cli
127.0.0.1:6379>?
127.0.0.1:6379> keys *
(error) NOAUTH Authentication required.? ? ? 沒有登錄
127.0.0.1:6379> auth 123456? ? ?登錄 一下
OK
127.0.0.1:6379> keys *? ? ? 查詢
(empty list or set)
127.0.0.1:6379>?
127.0.0.1:6379> exit? ? 退出
root@26b861b7ec37:/data#?
root@26b861b7ec37:/data# exit? ?退出redis
exit
[root@VM_0_13_centos ~]# firewall-cmd --query-port=6379/tcp? ? ?6379端口開放了沒
FirewallD is not running
[root@VM_0_13_centos ~]# firewall-cmd --zone=public --add-port=6379/tcp -permanent? ? ? 開放6379端口
usage: see firewall-cmd man page? ?
firewall-cmd: error: unrecognized arguments: -permanent
[root@VM_0_13_centos ~]# firewall-cmd --reload? ? ?重啟防火墻
FirewallD is not running? ?
[root@VM_0_13_centos ~]# firewall-cmd --query-port=6379/tcp? ? ? 6379端口開放了沒
FirewallD is not running? ?
[root@VM_0_13_centos ~]#? ??
這個docker的內容還是很多的? ? ?這里希望開發人員能快速搭建環境? ?
redis如何運維? ?docker如何管理? ?不是這節課內容? ? 我講的你理解不了就下載windows版的
安裝起來方便后面章節的學習? ? 只要能把redis安裝起來都無所謂? ?
?
[root@VM_0_13_centos ~]# docker exec -it myredis5 bash? ? 登錄redis
root@26b861b7ec37:/data# redis-cli
127.0.0.1:6379> keys *
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth 123456? ?登錄密碼
OK
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379> set age 1? ?練習set集合
OK
127.0.0.1:6379> incr age
(integer) 2
127.0.0.1:6379> incr age
(integer) 3
127.0.0.1:6379> decr age
(integer) 2
127.0.0.1:6379> incrby age 2
(integer) 4
127.0.0.1:6379> decrby age 3
(integer) 1
127.0.0.1:6379> setex 10 yangjiabin
(error) ERR wrong number of arguments for 'setex' command
127.0.0.1:6379> set name 10 yangjiabin
(error) ERR syntax error
127.0.0.1:6379> setex name 10 yangjiabin? ? ?設置name字段有效期為10秒鐘
OK
127.0.0.1:6379> get name? ?獲取name
"yangjiabin"
127.0.0.1:6379> get name
"yangjiabin"
127.0.0.1:6379> get name? ?超過10秒鐘就沒有數據了? ?一般有效期用在短信驗證碼上面
(nil)
127.0.0.1:6379> lpush queue1 1? ? ? ?list的使用場景? ? ?l-left? ?r-right? ?lpush-left push? ? rpop-right pop??
(integer) 1
127.0.0.1:6379> lpush queue1 2
(integer) 2
127.0.0.1:6379> lpop queue1? ? ? 雙向鏈表結構? 可以實現棧? 也可以實現隊列? 可以實現簡單的消息隊列
"2"
127.0.0.1:6379> lpush queue1 3
(integer) 2
127.0.0.1:6379> rpush queue1 4
(integer) 3
127.0.0.1:6379> rpop queue1
"4"
127.0.0.1:6379> lpop queue1
"3"
127.0.0.1:6379> lpop queue1
"1"
127.0.0.1:6379> lpop queue1
(nil)
127.0.0.1:6379> lpush queue2 a? ? ?向隊列推入abcd
(integer) 1
127.0.0.1:6379> lpush queue2 b
(integer) 2
127.0.0.1:6379> lpush queue2 c
(integer) 3
127.0.0.1:6379> lpush queue2 d? ? 最新的在最上面
(integer) 4
127.0.0.1:6379> lrange queue2 0 4? ? ?這種適合最新文章的排序展示
1) "d"
2) "c"
3) "b"
4) "a"
127.0.0.1:6379> sadd "user:101" 1? ? 用戶感興趣的內容
(integer) 1
127.0.0.1:6379> sadd "user:101" 2
(integer) 1
127.0.0.1:6379> sadd "user:102" 1
(integer) 1
127.0.0.1:6379> sadd "user:102" 3
(integer) 1
127.0.0.1:6379> sinter "user:101" "user:102"? ? 101和102用戶的交集
1) "1"
127.0.0.1:6379> sunion "user:101" "user:102"? ?101和102用戶的并集
1) "1"
2) "2"
3) "3"
127.0.0.1:6379> hset user102 name yangjiabin? ? ? ?hash存儲對象
(integer) 1
127.0.0.1:6379> hset user102 age 18
(integer) 1
127.0.0.1:6379> hset user102 sex male
(integer) 1
127.0.0.1:6379> hget user103
(error) ERR wrong number of arguments for 'hget' command
127.0.0.1:6379> hget user102
(error) ERR wrong number of arguments for 'hget' command
127.0.0.1:6379> hget user102 name
"yangjiabin"
127.0.0.1:6379> hget user102 age
"18"
127.0.0.1:6379> hget user102 sex
"male"
127.0.0.1:6379>?
127.0.0.1:6379> zadd hot_product 100 apple? ? 熱銷商品可以按照分數排序
(integer) 1
127.0.0.1:6379> zadd hot_product 99 htc
(integer) 1
127.0.0.1:6379> zadd hot_product 98 hawe
(integer) 1
127.0.0.1:6379> zrange hot_product 0 -1? ? ?正序
1) "hawe"
2) "htc"
3) "apple"
127.0.0.1:6379> zrevrange hot_product 0 -1? ? 逆序
1) "apple"
2) "htc"
3) "hawe"
127.0.0.1:6379>?
127.0.0.1:6379> exit? ? 退出
root@26b861b7ec37:/data# exit? ?退出
exit
[root@VM_0_13_centos ~]#?
第11章終于看完了?
?
?
第12章整合分布式文件系統fastdfs
算過了? ? 全是封裝號調用了一下
?
第13章服務器推送技術? ??
sse 和websoket? websocket更加通用一些? ??
?
?
第14章消息隊列的整合與使用
算了? ? 消息隊列? 算了
?
?第十五章 郵件發送的整合與使用
這個看代碼好了? ? 還是比較簡單的??
這個視頻對應的docker不是很好? ?只是輔助springboot搭建一下環境而已??
講解的太快了。
?
第16章響應式框架webflux
這個可能史下一代的框架? 代替springboot的
還是不是很成熟 有bug
全部看完了
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
總結
以上是生活随笔為你收集整理的docker 买了腾讯服务器后的学习的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 怎么免费建设个人网站(怎么免费建设个人网
- 下一篇: 网络公司怎么备案(网络公司怎么备案流程)