练习:docker部署
Posted by1314
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了练习: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?
docker部署nginx,tomcat 练习
docker部署nginx步骤
- docker pull nginx
- docker run -d --name nginx01 -p 3344:80 nginx #设置端口映射,暴露到公网
- 使用curl localhost:3344 进行测试 ,会跳出nginx欢迎界面说明跑起来成功了
拓扑图如下:
思考:弊端是每次需要在运行到容器里进行部署,比较麻烦,是否可以容器外部提供映射路径,镜像里改,容器里也自动修改??
其实是可以的,后期需要用到 -v 数据卷的技术.
docker部署tomcat步骤
步骤同上,略,我们会发现这个容器部署好后,tomcat无法访问.
因为阿里的镜像有些事阉割版,把非必要部分都去除了.但是可以发现tomcat下的webapps.dist里有网页部署测试文件,
把这里的文件复制到webapps下, cp webapps.dist/* -r webapps/
就可以访问了
以上是关于练习:docker部署的主要内容,如果未能解决你的问题,请参考以下文章