docker 安装 Nginx、tomcat、ES(kuangshenstudy)

# 下载镜像 docker pull nginx 
# 运行测试
[root@localhost ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
nginx         latest    fa5269854a5e   5 days ago     142MB
hello-world   latest    feb5d9fea6a5   7 months ago   13.3kB
centos        latest    5d0da3dc9764   7 months ago   231MB
[root@localhost ~]# 

# --d 后台运行
# --name 给容器命名
# -p 宿主机端口,容器内部
[root@localhost ~]# docker run -d --name nginx1 -p 3344:80 nginx
ab25c65eab2a29029ecd1ac3a0b858c905276229b9a8cec29dc6cefe8bf88baa
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS                                   NAMES
ab25c65eab2a   nginx     "/docker-entrypoint.…"   5 seconds ago   Up 4 seconds   0.0.0.0:3344->80/tcp, :::3344->80/tcp   nginx1
[root@localhost ~]# curl localhost:3344

# 进入容器
[root@localhost ~]# docker run -it --name a1 -p 3321:80 nginx /bin/bash
root@645610e408b3:/# [root@localhost ~]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS         PORTS                                   NAMES
645610e408b3   nginx     "/docker-entrypoint.…"   10 seconds ago   Up 9 seconds   0.0.0.0:3321->80/tcp, :::3321->80/tcp   a1
[root@localhost ~]# docker attach a1
root@645610e408b3:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
root@645610e408b3:/# cd /etc/nginx/
root@645610e408b3:/etc/nginx# ls
conf.d          mime.types  nginx.conf   uwsgi_params
fastcgi_params  modules     scgi_params
root@645610e408b3:/etc/nginx# 

# 官方的使用
docker run -it --rm tomcat:9.0

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

# 下载在启动
docker run -it --rm tomcat:9.0

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

# 测试访问没有问题

# 进入容器 
[root@localhost ~]# docker exec -it b1 /bin/bash
root@7c18ed21ce6d:/usr/local/tomcat# cd webapps
root@7c18ed21ce6d:/usr/local/tomcat/webapps# ls
root@7c18ed21ce6d:/usr/local/tomcat/webapps# 

# 发现问题:1、linux命令少了 2、没有webapps 阿里云镜像的原因,默认是最小的镜像,默认把不必要的都剔除掉
# 保证最小可运行环境
# es 暴露的端口很多!
# es 十分的耗内存
# es 的数据一般需要放置到安全目录! 挂载
# --net somenetwork ? 网络配置  

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

# 启动后 docker stats 查看cpu的状态
# 测试一下es是否成功了
[root@localhost ~]# curl localhost:9200
{
  "name" : "899114e3c43e",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "oEHVNORnQteiBIm5h3cRkA",
  "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"
}
[root@localhost ~]#

# 赶紧关闭,增加内存的限制  -e 环境配置修改
docker run -d --name elasticsearch02 -p 9200:9200 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms64m -Xmx512m"  elasticsearch:7.6.2

 

你可能感兴趣的:(docker,linux,centos,docker,云计算)