Docker入门第六章

部署Nginx


#1.搜索镜像 search 建议大家去docker搜索,可以看到帮助文档
#2.下载镜像	pull
#3.运行测试
[root@localhost ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
nginx        latest    08b152afcfae   3 weeks ago    133MB
centos       latest    300e315adb2f   8 months ago   209MB

# -d 后台运行
# --name 给容器命名
# -p 宿主机端口,容器内部端口

[root@localhost ~]# docker run -d --name nginx01 -p 3344:80 nginx
98fe864057ca7582ada2fc6b0b6f0fa3c40416481fb6ad7663931916315e84be
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS         PORTS                                   NAMES
98fe864057ca   nginx     "/docker-entrypoint.…"   13 seconds ago   Up 6 seconds   0.0.0.0:3344->80/tcp, :::3344->80/tcp   nginx01
[root@localhost ~]# curl localhost:3344

#进入容器
[root@localhost ~]# docker  exec -it nginx01 /bin/bash
root@98fe864057ca:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
root@98fe864057ca:/# cd /etc/nginx/
root@98fe864057ca:/etc/nginx# ls
conf.d  fastcgi_params  mime.types  modules  nginx.conf  scgi_params  uwsgi_params

部署Tomcat


#官方的使用
docker run -it --rm tomcat:9.0
 
#我们之前的启动都是后台,停止了容器之后,容器还是可以查到  docker run -it --rm,一般用来测试,用完就删除

#下载再启动
docker pull tomcat

#启动运行
docker run -d -p 3355:8080 --name tomcat01 tomcat

#测试访问没有问题

#进入容器
[root@localhost ~]# docker exec -it tomcat01 /bin/bash

#发现问题:
#  1.linux命令少了,2.webapps没有文件,阿里云镜像的原因,默认是最小的镜像,所有不必要的都剔除掉
#  保证最小可运行环境

部署ES+Kibana


# es 暴露的端口很多!
# es 十分的耗内存
# es 的数据一啊不能需要放置到安全目录!挂载
# --net somenetwork 是网络配置
docker run -d --name elasticsearch --net somenetwork -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:tag

#启动 elaticsearch
docker run -d --name elasticsearch  -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:7.6.2

#测试一下es是否成功
[root@localhost ~]# curl localhost:9200
{
  "name" : "566b9cc477be",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "IAy-Zq6LTqa2dhC8LLCBSA",
  "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 stats 查看cpu的状态

可以看到我的虚拟机是1G内存,这个ElasticSearch占用了我545.6M,相当于占用了我56.11%的内存,我们可以对ES增加内存的限制,修改配置文件,

我们可以通过-e参数进行环境配置的修改,先关闭掉elasticsearch

#关闭掉刚刚启动的ElasticSearch
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE                 COMMAND                  CREATED          STATUS          PORTS                                                                                  NAMES
566b9cc477be   elasticsearch:7.6.2   "/usr/local/bin/dock…"   37 minutes ago   Up 36 minutes   0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp   elasticsearch
[root@localhost ~]# docker stop 566b9cc477be

#重新运行一个ElasticSearch实例
docker run -d --name elasticsearch02  -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms64m -Xmx512m" elasticsearch:7.6.2

#启动成功之后查看是否能够正常访问
[root@localhost ~]# curl localhost:9200
{
  "name" : "9ca8bdf59d48",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "xgzM52tdTRyF-xqCzuPdBg",
  "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 stats

可以看到此时占用内存才399M,依然正常访问成功

posted @ 2021-08-15 11:23  吕世昊  阅读(41)  评论(0编辑  收藏  举报