实践一:
docker部署nginx
docker 安装Nginx
# 1、搜素镜像 search
# 2、下载镜像 pull
# 3、运行测试
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest dd34e67e3371 5 days ago 133MB
centos latest 300e315adb2f 8 months ago 209MB
# -d 后台运行
# --name 给容器命名
# -p 宿主机端口:暴露端口
[root@localhost ~]# docker run -d --name nginx01 -p 80:80 nginx
81287a90b5219fc2a895a43bf8aebb67c63ba4e3db37d7d2a1e92248614ff922
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
81287a90b521 nginx "/docker-entrypoint.…" 6 seconds ago Up 3 seconds 0.0.0.0:80->80/tcp, :::80->80/tcp nginx01
[root@localhost ~]# curl localhost
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
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>
[root@localhost ~]#
[root@localhost ~]# docker exec -it nginx01 /bin/bash
root@81287a90b521:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
root@81287a90b521:/# cd /etc/nginx/
root@81287a90b521:/etc/nginx# ls
conf.d fastcgi_params mime.types modules nginx.conf scgi_params uwsgi_params
实践二:
docker部署tomcat
# 官方的使用
docker run -it --rm tomcat:9.0 # 一般用于测试,用完即删
# 下载再启动
docker pull tomcat
# 启动运行
[root@localhost ~]# docker run -d -p 80:8080 --name tomcat01 tomcat
# 测试访问没有问题
# 进入容器
[root@localhost ~]# docker exec -it tomcat01 /bin/bash
# 发现问题:1、linux命令少了。2、没有webapps。阿里云镜像的原因:默认是最小的镜像,所有不必要的都剔除了,保证最小可运行的环境。
实践三:
部署es+kibana
# es 暴露的端口很多
# es 十分消耗内存
# es 的数据一般需要放置到安全目录!挂载
# --net somenetwork 网络配置
# 启动 elasticsearch
docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:7.6.2
# 启动es linux容易卡顿
docker stats 查看cpu的状态
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
68d8d752eff9 elasticsearch 0.21% 1.024GiB / 1.777GiB 57.62% 3.44kB / 4.33kB 585MB / 10.2MB 49
72ea9169fc1f tomcat01 0.12% 76.85MiB / 1.777GiB 4.22% 13.2kB / 138kB 226MB / 0B 34
#测试es是否成功
[root@localhost ~]# curl localhost:9200
{
"name" : "68d8d752eff9",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "ZD41tjcnQUCYhsScPXDW0Q",
"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"
}
# 消耗内存大,修改配置文件 -e 环境配置修改
docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="Xms64m Xmx512m" elasticsearch:7.6.2
可视化
-
portainer
# 什么是portainer? # docker 图形化界面管理工具!提供一个后台面板供我们操作 docker run -d -p 8088:9000 --restart=always -v /var/run/docker.sock:/var/run/docker.sock --privileged=true portainer/portainer
-
Rancher(CI/CD)