1.🏀Docker部署Nginx
1.⚽️搜索镜像
#1.搜索镜像
docker search nginx
[root@VM-16-15-centos /]# docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 14207 [OK]
jwilder/nginx-proxy Automated Nginx reverse proxy for docker con… 1932 [OK]
richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable of… 797 [OK]
linuxserver/nginx An Nginx container, brought to you by LinuxS… 137
jc21/nginx-proxy-manager Docker container for managing Nginx proxy ho… 123
tiangolo/nginx-rtmp Docker image with Nginx using the nginx-rtmp… 107
2.⚽️下载镜像
#2.下载镜像 pull
docker pull nginx
[root@VM-16-15-centos /]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
a2abf6c4d29d: Pull complete
a9edb18cadd1: Pull complete
589b7251471a: Pull complete
186b1aaa4aa6: Pull complete
b4df32aa5a72: Pull complete
a0bcbecc962e: Pull complete
Digest: sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
3.⚽️查看镜像
#3.查看镜像
docker images
[root@VM-16-15-centos /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 605c77e624dd 5 months ago 141MB
centos latest 5d0da3dc9764 8 months ago 231MB
4.⚽️启动镜像
#4.进入镜像
docker run -d --name nginx01 -p 6000:80 nginx
-d 后台运行
--name 给容器命名
-p 6000:80 将宿主机的端口6000映射到该容器的80端口 通过公网的6000端口的时候,就相当于访问容器的80
[root@VM-16-15-centos /]# docker run -d --name nginx01 -p 6000:80 nginx
aaab1ceda8084ee9fe9a9ffd751fe4ed7579ee67ea4d15f40ecd7226b4bdc620
5.⚽️查看镜像是否启动
#5.查看容器是否启动
[root@VM-16-15-centos /]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
aaab1ceda808 nginx "/docker-entrypoint.…" 10 seconds ago Up 8 seconds 0.0.0.0:6000->80/tcp, :::6000->80/tcp nginx01
6.⚽️测试访问nginx
#6.测试访问nginx
[root@VM-16-15-centos /]# curl localhost:6000
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
7.⚽️进入Nginx配置文件
[root@VM-16-15-centos /]# docker exec -it nginx01 /bin/bash
root@aaab1ceda808:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
root@aaab1ceda808:/# cd /etc/nginx
root@aaab1ceda808:/etc/nginx# ls
conf.d fastcgi_params mime.types modules nginx.conf scgi_params uwsgi_params
8.⚽️端口暴露的概念
9.⚽️用浏览器访问阿里云服务器
首先开放阿里云的6000端口,直接通过访问公网,来访问容器里面的nginx
10.⚽️停止Nginx
root@aaab1ceda808:/etc/nginx# exit
exit
[root@VM-16-15-centos /]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
aaab1ceda808 nginx "/docker-entrypoint.…" About an hour ago Up About an hour 0.0.0.0:6000->80/tcp, :::6000->80/tcp nginx01
[root@VM-16-15-centos /]# docker stop aaab1ceda808
aaab1ceda808
再次访问公网ip,显示错误
每次改动都需要进入nginx配置文件,都需要进入容器内部?十分麻烦,此时可以在容器外部提供一个映射路径,达到在容器外部修改文件名,容器内部自动修改 -v 数据卷!!!
2.🏀Docler部署Tomcat
Tomcat与上述部署Nginx一样
#官方的使用
docker run -it tomcat:9.0
#我们之前的启动都是后台的,停止了后,容器还是可以查到 docker run -it --rm; 一般用来测试,用完就删除
1.⚽️下载启动
[root@VM-16-15-centos /]# docker pull tomcat
Using default tag: latest
latest: Pulling from library/tomcat
0e29546d541c: Pull complete
9b829c73b52b: Pull complete
cb5b7ae36172: Pull complete
6494e4811622: Pull complete
668f6fcc5fa5: Pull complete
dc120c3e0290: Pull complete
8f7c0eebb7b1: Pull complete
77b694f83996: Pull complete
0f611256ec3a: Pull complete
4f25def12f23: Pull complete
Digest: sha256:9dee185c3b161cdfede1f5e35e8b56ebc9de88ed3a79526939701f3537a52324
Status: Downloaded newer image for tomcat:latest
docker.io/library/tomcat:latest
2.⚽️查看镜像
[root@VM-16-15-centos /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 605c77e624dd 5 months ago 141MB
tomcat latest fb5657adc892 5 months ago 680MB
centos latest 5d0da3dc9764 8 months ago 231MB
3.⚽️启动镜像
[root@VM-16-15-centos /]# docker run -d -p 3355:8080 --name tomcat01 tomcat
c99e683ac6514d52095ef949aeee27a20525981244d83189e00993ab9697eabc
4.⚽️查看镜像是否启动
[root@VM-16-15-centos /]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c99e683ac651 tomcat "catalina.sh run" 33 seconds ago Up 32 seconds 0.0.0.0:3355->8080/tcp, :::3355->8080/tcp tomcat01
5.⚽️测试访问tomcat(失败)
#进入容器
[root@VM-16-15-centos /]# docker exec -it tomcat01 /bin/bash
#发现问题:
#1.linux命令少了
#2.没有webapps.阿里云镜像的原因。默认是最小镜像,所有不必要的都要删掉,保证最小可运行环境
6.⚽️修改配置
#因为没有webapps.阿里云镜像的原因。默认是最小镜像,所有不必要的都要删掉,保证最小可运行环境
#但是所需要的配置在webapps.dist当中,将webapps.dist中的文件复制到webapps中就可以正常访问了
root@c99e683ac651:/usr/local/tomcat# cp -r webapps.dist/* webapps
7.⚽️再次访问
可以在外部提供一个映射路径,webapps,我们就可以在外部放置项目,自动同步到内部 -v 数据卷!!!
例如 dokcer 容器 tomcat+网站 docker mysql:之前都是把mysql删除,删库跑路,但是如果把docker删了,mysql也没了,这是不可以的。之后通过数据卷解决一系列问题
3.🏀Docker部署ES+KIBANA
# es 暴露的端口很多!
# es 十分的耗内存
# es 的数据一般需要放置到安全目录!挂载
# --net somenetwork ? 网络配置
#启动 elastisearch
#(重要的事情说三遍,用下面修改配置的那个命令,不然这个命令你服务器会卡死,了解这个就行)
#(重要的事情说三遍,用下面修改配置的那个命令,不然这个命令你服务器会卡死,了解这个就行)
#(重要的事情说三遍,用下面修改配置的那个命令,不然这个命令你服务器会卡死,了解这个就行)
docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:7.6.2 #(不建议用这个,服务器会卡主)
#启动 linux就卡住了 what???? docker stats 查看 cpu 状态
#测试一下es是否成功
[root@iZ2zeaoalqnp4d3d7aiqu4Z ~]# curl localhost:9200
{
"name" : "cb2e99df7271",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "G42_IAvdQwWzbVHPJ-NdqA",
"version" : {
"number" : "7.6.2",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "ef48eb35cf30adf4db14086e8aabd07ef6fb113f",
"build_date" : "2020-03-26T06:34:37.794943Z",
"build_snapshot" : false,
"lucene_version" : "8.4.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
#停止整个docker(一般不建议)
#查看 docker stats
#赶紧关闭,增加内存的限制 ,修改配置文件 -e 环境配置修改
docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms128m -Xmx512m" elasticsearch:7.6.2
#查看docker stats
#测试一下es是否成功
[root@iZ2zeaoalqnp4d3d7aiqu4Z ~]# curl localhost:9200
{
"name" : "cb2e99df7271",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "G42_IAvdQwWzbVHPJ-NdqA",
"version" : {
"number" : "7.6.2",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "ef48eb35cf30adf4db14086e8aabd07ef6fb113f",
"build_date" : "2020-03-26T06:34:37.794943Z",
"build_snapshot" : false,
"lucene_version" : "8.4.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
4.🏀图形化管理工具Portaniner安装
- Portaniner是Docker的图形化管理工具,类似的工具还有Rancher(CI/CD再用)
- portainer是Docker图形界面管理工具!提供一个后台面板供我们操作!
1.⚽️下载Portaniner镜像并运行
- ,设置本机映射端口为8088
docker run -d -p 8088:9000 --restart=always -v /var/run/docker.sock:/var/run/docker.sock --privileged=true portainer/portainer
2.⚽️访问测试外网8088
- 要设置阿里云的8088安全组
- 访问外网测试:http://ip:8088/
- 填写上述密码,进入该页面,选择Local。