docker入门(五)—— 小练习,docker安装nginx、elasticsearch

时间:2024-03-25 20:54:19

练习

docker 安装 nginx

# 搜素镜像
[root@iZbp15293q8kgzhur7n6kvZ home]# docker search nginx
NAME                                              DESCRIPTION                                     STARS     OFFICIAL
nginx                                             Official build of Nginx.                        19711     [OK]
......
# 拉取镜像
[root@iZbp15293q8kgzhur7n6kvZ home]# 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
# 通过镜像启动容器
# --name 给容器命名
# -p 3500<->80 端口映射(本机端口:容器内端口),外部通过3500端口访问
[root@iZbp15293q8kgzhur7n6kvZ home]# docker run -d --name mynginx -p 3500:80 nginx
8d54bf57c5577257227c90db0d8fdfe3ba769b294e4a49e5500c7fe6e6a904d4
[root@iZbp15293q8kgzhur7n6kvZ home]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS                                   NAMES
8d54bf57c557   nginx     "/docker-entrypoint.…"   13 seconds ago   Up 12 seconds   0.0.0.0:3500->80/tcp, :::3500->80/tcp   mynginx
[root@iZbp15293q8kgzhur7n6kvZ home]# curl localhost:3500
<!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>

这样就完成 nginx 的安装

也可以在外部浏览器访问,输入地址服务器公网ip:3500即可访问,如果无法访问说明没有配置安全组,需要在安全组中把3500端口开放

在这里插入图片描述

docker 安装 elasticsearch

# -p 可以同时暴露多个端口
# -e 环境配置,一般在镜像的文档中查看  hub.docker.com
[root@iZbp15293q8kgzhur7n6kvZ home]# docker run -d --name myelastaicsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:7.8.0
Unable to find image 'elasticsearch:7.8.0' locally
7.8.0: Pulling from library/elasticsearch
524b0c1e57f8: Pull complete 
7a096b8f20be: Pull complete 
9dd8117fbfec: Pull complete 
335891dbdd0e: Pull complete 
dfce820717b4: Pull complete 
82d3459719f7: Pull complete 
2e79822fece3: Pull complete 
2f80b981dd6a: Pull complete 
05f8a08da0ba: Pull complete 
Digest: sha256:945f80960f2ad1bd4b88bd07a9ba160d22d4285bbc8a720d052379006d5d57a6
Status: Downloaded newer image for elasticsearch:7.8.0
bad6ece441159ee80c53aa5e30403e7f82ea96ab4ce8315a3e2c6fb81f0bbbca
[root@iZbp15293q8kgzhur7n6kvZ home]# curl localhost:9200
{
  "name" : "bad6ece44115",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "t4WJEW-oQ-CiSiI1n1YtHQ",
  "version" : {
    "number" : "7.8.0",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "757314695644ea9a1dc2fecd26d1a43856725e65",
    "build_date" : "2020-06-14T19:35:50.234439Z",
    "build_snapshot" : false,
    "lucene_version" : "8.5.1",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}