1. 程式人生 > 其它 >docker 之常見應用部署

docker 之常見應用部署

https://hub.docker.com/ 查詢需要的映象和配置說明

一、Portainer

Portainer是Docker的圖形化管理工具,提供狀態顯示面板、應用模板快速部署、容器映象網路資料卷的基本操作(包括上傳下載映象,建立容器等操作)

拉取映象

[root@yt yum.repos.d]#  docker pull  portainer/portainer
Using default tag: latest
latest: Pulling from portainer/portainer
94cfa856b2b1: Pull complete 
49d59ee0881a: Pull complete 
a2300fd28637: Pull complete 
Digest: sha256:fb45b43738646048a0a0cc74fcee2865b69efde857e710126084ee5de9be0f3f
Status: Downloaded newer image 
for portainer/portainer:latest docker.io/portainer/portainer:latest

檢視映象

[root@yt ~]# docker images
REPOSITORY            TAG       IMAGE ID       CREATED        SIZE
portainer/portainer   latest    580c0e4e98b0   9 months ago   79.1MB

建立資料卷用於持久化Portainer資料

[root@yt ~]#docker volume create portainer_data
portainer_data  

執行

[root@yt ~]# docker run -d -p 9000:9000 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer
142ecf88d17f9da25bdd6d809aa2e50ba20c2e21e6cf45bf7dedcdc5817e31ab

用宿主機9000埠關聯容器中的9000埠,並給容器起名為portainer
restart=always是指docker重啟的時候會同時重啟

5、訪問 iP:9000

建立使用者

如果是單機版,直接選擇Local,點選連線

二、mysql

拉取mysql,指定版本

[root@yt ~]# docker pull mysql:5.7.28
5.7.28: Pulling from library/mysql
804555ee0376: Pull complete 
c53bab458734: Pull complete 
ca9d72777f90: Pull complete 
2d7aad6cb96e: Pull complete 
8d6ca35c7908: Pull complete 
6ddae009e760: Pull complete 
327ae67bbe7b: Pull complete 
31f1f8385b27: Pull complete 
a5a3ad97e819: Pull complete 
48bede7828ac: Pull complete 
380afa2e6973: Pull complete 
Digest: sha256:b38555e593300df225daea22aeb104eed79fc80d2f064fde1e16e1804d00d0fc
Status: Downloaded newer image for mysql:5.7.28
docker.io/library/mysql:5.7.28

檢視

[root@yt ~]# docker images 
REPOSITORY            TAG       IMAGE ID       CREATED        SIZE
portainer/portainer   latest    580c0e4e98b0   9 months ago   79.1MB
mysql                 5.7.28    db39680b63ac   2 years ago    437MB

執行

[root@yt ~]# docker run  -di --name mymysql -e MYSQL_ROOT_PASSWORD=123456 -p 3306:3306 -d mysql:5.7.28 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
34da9b18ace04e7c65ed959f673de4cb3d976f59e957c94a2f9ef933f6927714
-e MYSQL_ROOT_PASSWORD=密碼即root使用者的密碼

--character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci 設定編碼集

測試

三、Elasticsearch

Elasticsearch 是一個分散式的 RESTful 風格的搜尋和資料分析引擎

拉取映象

[root@yt ~]# docker pull docker.io/elasticsearch:6.7.2
6.7.2: Pulling from library/elasticsearch
8ba884070f61: Pull complete 
b331515ab671: Pull complete 
bcf2b1fa0e4a: Pull complete 
f7a17ff6a854: Pull complete 
3c509982db17: Pull complete 
268f1d6adb82: Pull complete 
9e0e44f72b02: Pull complete 
Digest: sha256:59144dbc396225d13980bb801eac65c83f9862ea08a3c5bef932ca91e0eda84e
Status: Downloaded newer image for elasticsearch:6.7.2
docker.io/library/elasticsearch:6.7.2

檢視

[root@yt ~]# docker images
REPOSITORY            TAG       IMAGE ID       CREATED        SIZE
portainer/portainer   latest    580c0e4e98b0   9 months ago   79.1MB
mysql                 5.7.28    db39680b63ac   2 years ago    437MB
elasticsearch         6.7.2     2982ba071059   2 years ago    863MB
View Code

執行

[root@yt ~]# docker run -d  --name=myse  -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node"  elasticsearch:6.7.2
c1702f6daa4e70b27142eb96f8aec4c44a54a60dbef3811dd2ea76bbc731bfbb
-e "discovery.type=single-node" 設定為單節點

訪問 IP:9200

四、elasticsearch head外掛監控管理

拉取映象

[root@yt ~]# docker pull mobz/elasticsearch-head:5
5: Pulling from mobz/elasticsearch-head
75a822cd7888: Pull complete 
57de64c72267: Pull complete 
4306be1e8943: Pull complete 
871436ab7225: Pull complete 
0110c26a367a: Pull complete 
1f04fe713f1b: Pull complete 
723bac39028e: Pull complete 
7d8cb47f1c60: Pull complete 
7328dcf65c42: Pull complete 
b451f2ccfb9a: Pull complete 
304d5c28a4cf: Pull complete 
4cf804850db1: Pull complete 
Digest: sha256:55a3c82dd4ba776e304b09308411edd85de0dc9719f9d97a2f33baa320223f34
Status: Downloaded newer image for mobz/elasticsearch-head:5
docker.io/mobz/elasticsearch-head:5
[root@yt ~]# docker run -d -p 9100:9100 docker.io/mobz/elasticsearch-head:5
755ef6b9e9eac132078845598fea9c1fc773758d615ba21124bffaa3f6a737c7

訪問 IP:9100

配置跨域
[root@yt ~]# docker exec -it myse bash
[root@c1702f6daa4e elasticsearch]# ls
LICENSE.txt  README.textile  config  lib   modules
NOTICE.txt   bin             data    logs  plugins
[root@c1702f6daa4e elasticsearch]# cd config/
[root@c1702f6daa4e config]# ls
elasticsearch.keystore  log4j2.properties  users
elasticsearch.yml       role_mapping.yml   users_roles
jvm.options             roles.yml
[root@c1702f6daa4e config]# cat elasticsearch.yml 
cluster.name: "docker-cluster"
network.host: 0.0.0.0

[root@yt ~]# docker cp myse:/usr/share/elasticsearch/config/elasticsearch.yml ./

修改如下:cluster.name:自定義叢集名稱
network.host:當前es節點繫結的ip地址
http.cors.enabled:是否支援跨域,
http.cors.allow-origin:當設定允許跨域

[root@yt ~]# cat elasticsearch.yml
cluster.name: "docker-cluster"
network.host: 0.0.0.0
http.cors.enabled: true
http.cors.allow-origin: "*"

[root@yt ~]# docker cp elasticsearch.yml myse:/usr/share/elasticsearch/config/

重啟

[root@yt ~]# docker restart myse
myse
[root@yt ~]# docker restart 755ef6b9e9eac132078845598fea9c1fc773758d615ba21124bffaa3f6a737c7
755ef6b9e9eac132078845598fea9c1fc773758d615ba21124bffaa3f6a737c7

再次連線

六、Portainer容器管理

對容器的操作,啟動,停止.....

新增容器

訪問:IP:8080