练习:docker部署
部署nginx
- 搜索镜像(最好取hub官网搜索一下)--search
- 拉取下载镜像--pull
- 使用后台运行,并起名字,-p 宿主机端口:容器内部端口
[root@bytest01 ~]# docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 18336 [OK]
linuxserver/nginx An Nginx container, brought to you by LinuxS… 188
bitnami/nginx Bitnami nginx Docker Image 155 [OK]
ubuntu/nginx Nginx, a high-performance reverse proxy & we… 84
privatebin/nginx-fpm-alpine PrivateBin running on an Nginx, php-fpm & Al… 72 [OK]
bitnami/nginx-ingress-controller Bitnami Docker Image for NGINX Ingress Contr… 23 [OK]
rancher/nginx-ingress-controller 11
kasmweb/nginx An Nginx image based off nginx:alpine and in… 4
ibmcom/nginx-ingress-controller Docker Image for IBM Cloud Private-CE (Commu… 4
bitnami/nginx-ldap-auth-daemon 3
bitnami/nginx-exporter 3
rapidfort/nginx RapidFort optimized, hardened image for NGINX 3
circleci/nginx This image is for internal use 2
rancher/nginx 2
rancher/nginx-ingress-controller-defaultbackend 2
vmware/nginx 2
bitnami/nginx-intel 1
rapidfort/nginx-official RapidFort optimized, hardened image for NGIN… 1
vmware/nginx-photon 1
rancher/nginx-conf 0
ibmcom/nginx-ppc64le Docker image for nginx-ppc64le 0
ibmcom/nginx-ingress-controller-ppc64le Docker Image for IBM Cloud Private-CE (Commu… 0
rancher/nginx-ssl 0
rapidfort/nginx-ib RapidFort optimized, hardened image for NGIN… 0
continuumio/nginx-ingress-ws 0
[root@bytest01 ~]# 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
[root@bytest01 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 605c77e624dd 15 months ago 141MB
centos 6 5bf9684f4720 18 months ago 194MB
centos latest 5d0da3dc9764 18 months ago 231MB
[root@bytest01 ~]# docker run -d --name nginx01 -p 3344:80 nginx
e04554f7a734e198df6fe61fb64ad040255e354372b9c6f923f5a5eff5485f31
[root@bytest01 ~]#
[root@bytest01 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e04554f7a734 nginx "/docker-entrypoint.…" 8 seconds ago Up 5 seconds 0.0.0.0:3344->80/tcp nginx01
[root@bytest01 ~]# curl localhost:3344
<!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 配置文件都需要进入容器内部十分麻烦,我们可以在容器恩爱不提供一个映射路径,可以达到在容器外修改文件名,内部自动修改?
-v数据卷技术
部署 tomcat
docker run -it --rm tomcat:9.0 #之前的启动都是后台的,停止容器还是可以查到,官方写法用完就删通用于测试
docker pull tomcat:9.0
docker run -d --name tomcat01 -p 9000:80 tomcat
docker exec -it tomcat01 /bin/bash #进入容器
问题:发现linux命令减少,阿里云镜像获取最小镜像,能删的都删了
部署 es
- es 暴露的端口很多
- es 需要放到安全目录中,挂载
- es 很费内存
--net somenetwork ? 网络配置
docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:8.6.2
使用 docker stats 查看 cpu状态
docker stats
增加内存限制通过-e 环境修改配置
docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms64m -Xms512m" elasticsearch:8.6.2 #最大内存512MB
如何使用 kibana 去连接 es?
哪有什么胜利可言,坚持意味着一切。如想使用请备注转载链接~