【四、docker容器部署】

本文涉及的产品
容器服务 Serverless 版 ACK Serverless,317元额度 多规格
容器镜像服务 ACR,镜像仓库100个 不限时长
容器服务 Serverless 版 ACK Serverless,952元额度 多规格
简介: #### 1.⚽️搜索镜像```shell#1.搜索镜像 docker search nginx[root@VM-16-15-centos /]# docker search nginxNAME DESCRIPTION

1.🏀Docker部署Nginx

1.⚽️搜索镜像

#1.搜索镜像 
docker search nginx

[root@VM-16-15-centos /]# docker search nginx
NAME                               DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
nginx                              Official build of Nginx.                        14207     [OK]       
jwilder/nginx-proxy                Automated Nginx reverse proxy for docker con…   1932                 [OK]
richarvey/nginx-php-fpm            Container running Nginx + PHP-FPM capable of…   797                  [OK]
linuxserver/nginx                  An Nginx container, brought to you by LinuxS…   137                  
jc21/nginx-proxy-manager           Docker container for managing Nginx proxy ho…   123                  
tiangolo/nginx-rtmp                Docker image with Nginx using the nginx-rtmp…   107  

2.⚽️下载镜像

#2.下载镜像 pull
docker pull nginx

[root@VM-16-15-centos /]# 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

3.⚽️查看镜像

#3.查看镜像
docker images
[root@VM-16-15-centos /]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
nginx        latest    605c77e624dd   5 months ago   141MB
centos       latest    5d0da3dc9764   8 months ago   231MB

4.⚽️启动镜像

#4.进入镜像
docker run -d --name nginx01 -p 6000:80 nginx
-d 后台运行
--name 给容器命名
-p 6000:80 将宿主机的端口6000映射到该容器的80端口 通过公网的6000端口的时候,就相当于访问容器的80

[root@VM-16-15-centos /]# docker run -d --name nginx01 -p 6000:80 nginx
aaab1ceda8084ee9fe9a9ffd751fe4ed7579ee67ea4d15f40ecd7226b4bdc620

5.⚽️查看镜像是否启动

#5.查看容器是否启动
[root@VM-16-15-centos /]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS         PORTS                                   NAMES
aaab1ceda808   nginx     "/docker-entrypoint.…"   10 seconds ago   Up 8 seconds   0.0.0.0:6000->80/tcp, :::6000->80/tcp   nginx01

6.⚽️测试访问nginx

#6.测试访问nginx

[root@VM-16-15-centos /]# curl localhost:6000
<!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>

7.⚽️进入Nginx配置文件

[root@VM-16-15-centos /]# docker exec -it nginx01 /bin/bash
root@aaab1ceda808:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
root@aaab1ceda808:/# cd /etc/nginx
root@aaab1ceda808:/etc/nginx# ls
conf.d    fastcgi_params    mime.types  modules  nginx.conf  scgi_params  uwsgi_params

8.⚽️端口暴露的概念

1661159057047.png

9.⚽️用浏览器访问阿里云服务器

首先开放阿里云的6000端口,直接通过访问公网,来访问容器里面的nginx

1661159076023.png

10.⚽️停止Nginx

root@aaab1ceda808:/etc/nginx# exit
exit

[root@VM-16-15-centos /]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED             STATUS             PORTS                                   NAMES
aaab1ceda808   nginx     "/docker-entrypoint.…"   About an hour ago   Up About an hour   0.0.0.0:6000->80/tcp, :::6000->80/tcp   nginx01

[root@VM-16-15-centos /]# docker stop aaab1ceda808
aaab1ceda808

再次访问公网ip,显示错误

1661159088740.png

每次改动都需要进入nginx配置文件,都需要进入容器内部?十分麻烦,此时可以在容器外部提供一个映射路径,达到在容器外部修改文件名,容器内部自动修改 -v 数据卷!!!

2.🏀Docler部署Tomcat

Tomcat与上述部署Nginx一样

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

1.⚽️下载启动

[root@VM-16-15-centos /]# docker pull tomcat
Using default tag: latest
latest: Pulling from library/tomcat
0e29546d541c: Pull complete 
9b829c73b52b: Pull complete 
cb5b7ae36172: Pull complete 
6494e4811622: Pull complete 
668f6fcc5fa5: Pull complete 
dc120c3e0290: Pull complete 
8f7c0eebb7b1: Pull complete 
77b694f83996: Pull complete 
0f611256ec3a: Pull complete 
4f25def12f23: Pull complete 
Digest: sha256:9dee185c3b161cdfede1f5e35e8b56ebc9de88ed3a79526939701f3537a52324
Status: Downloaded newer image for tomcat:latest
docker.io/library/tomcat:latest

2.⚽️查看镜像

[root@VM-16-15-centos /]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
nginx        latest    605c77e624dd   5 months ago   141MB
tomcat       latest    fb5657adc892   5 months ago   680MB
centos       latest    5d0da3dc9764   8 months ago   231MB

3.⚽️启动镜像

[root@VM-16-15-centos /]# docker run -d -p 3355:8080 --name tomcat01 tomcat 
c99e683ac6514d52095ef949aeee27a20525981244d83189e00993ab9697eabc

4.⚽️查看镜像是否启动

[root@VM-16-15-centos /]# docker ps
CONTAINER ID   IMAGE     COMMAND             CREATED          STATUS          PORTS                                       NAMES
c99e683ac651   tomcat    "catalina.sh run"   33 seconds ago   Up 32 seconds   0.0.0.0:3355->8080/tcp, :::3355->8080/tcp   tomcat01

5.⚽️测试访问tomcat(失败)

1661159105094.png

#进入容器
[root@VM-16-15-centos /]# docker exec -it tomcat01 /bin/bash

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

6.⚽️修改配置

#因为没有webapps.阿里云镜像的原因。默认是最小镜像,所有不必要的都要删掉,保证最小可运行环境
#但是所需要的配置在webapps.dist当中,将webapps.dist中的文件复制到webapps中就可以正常访问了

root@c99e683ac651:/usr/local/tomcat# cp -r webapps.dist/* webapps

7.⚽️再次访问

1661159123765.png

可以在外部提供一个映射路径,webapps,我们就可以在外部放置项目,自动同步到内部 -v 数据卷!!!

例如 dokcer 容器 tomcat+网站 docker mysql:之前都是把mysql删除,删库跑路,但是如果把docker删了,mysql也没了,这是不可以的。之后通过数据卷解决一系列问题

3.🏀Docker部署ES+KIBANA

# es 暴露的端口很多!
# es 十分的耗内存
# es 的数据一般需要放置到安全目录!挂载
# --net somenetwork ? 网络配置

#启动 elastisearch 
#(重要的事情说三遍,用下面修改配置的那个命令,不然这个命令你服务器会卡死,了解这个就行)
#(重要的事情说三遍,用下面修改配置的那个命令,不然这个命令你服务器会卡死,了解这个就行)
#(重要的事情说三遍,用下面修改配置的那个命令,不然这个命令你服务器会卡死,了解这个就行)
docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:7.6.2  #(不建议用这个,服务器会卡主)


#启动 linux就卡住了 what????  docker stats 查看 cpu 状态

#测试一下es是否成功
[root@iZ2zeaoalqnp4d3d7aiqu4Z ~]# curl localhost:9200
{
  "name" : "cb2e99df7271",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "G42_IAvdQwWzbVHPJ-NdqA",
  "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(一般不建议)

#查看 docker stats

1661159138546.png

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


#查看docker stats

1661159150791.png

#测试一下es是否成功
[root@iZ2zeaoalqnp4d3d7aiqu4Z ~]# curl localhost:9200
{
  "name" : "cb2e99df7271",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "G42_IAvdQwWzbVHPJ-NdqA",
  "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"
}

1661159161981.png

4.🏀图形化管理工具Portaniner安装

  • Portaniner是Docker的图形化管理工具,类似的工具还有Rancher(CI/CD再用)
  • portainer是Docker图形界面管理工具!提供一个后台面板供我们操作!

1.⚽️下载Portaniner镜像并运行

  • ,设置本机映射端口为8088
docker run -d -p 8088:9000 --restart=always -v /var/run/docker.sock:/var/run/docker.sock --privileged=true portainer/portainer

2.⚽️访问测试外网8088

  • 要设置阿里云的8088安全组

1661159174268.png

1661159186837.png

  • 填写上述密码,进入该页面,选择Local。

1661159206113.png

1661159217931.png

相关实践学习
使用阿里云Elasticsearch体验信息检索加速
通过创建登录阿里云Elasticsearch集群,使用DataWorks将MySQL数据同步至Elasticsearch,体验多条件检索效果,简单展示数据同步和信息检索加速的过程和操作。
ElasticSearch 入门精讲
ElasticSearch是一个开源的、基于Lucene的、分布式、高扩展、高实时的搜索与数据分析引擎。根据DB-Engines的排名显示,Elasticsearch是最受欢迎的企业搜索引擎,其次是Apache Solr(也是基于Lucene)。 ElasticSearch的实现原理主要分为以下几个步骤: 用户将数据提交到Elastic Search 数据库中 通过分词控制器去将对应的语句分词,将其权重和分词结果一并存入数据 当用户搜索数据时候,再根据权重将结果排名、打分 将返回结果呈现给用户 Elasticsearch可以用于搜索各种文档。它提供可扩展的搜索,具有接近实时的搜索,并支持多租户。
目录
相关文章
|
3天前
|
JSON JavaScript 开发者
Composerize神器:自动化转换Docker运行命令至Compose配置,简化容器部署流程
【8月更文挑战第7天】Composerize神器:自动化转换Docker运行命令至Compose配置,简化容器部署流程
Composerize神器:自动化转换Docker运行命令至Compose配置,简化容器部署流程
|
1天前
|
Docker 容器
|
1天前
|
运维 Java Devops
阿里云云效操作报错合集之部署docker时遇到报错,该怎么办
本合集将整理呈现用户在使用过程中遇到的报错及其对应的解决办法,包括但不限于账户权限设置错误、项目配置不正确、代码提交冲突、构建任务执行失败、测试环境异常、需求流转阻塞等问题。阿里云云效是一站式企业级研发协同和DevOps平台,为企业提供从需求规划、开发、测试、发布到运维、运营的全流程端到端服务和工具支撑,致力于提升企业的研发效能和创新能力。
|
1天前
|
网络协议 Linux 网络安全
遇到Docker容器网络隔断?揭秘六种超级实用解决方案,轻松让Docker容器畅游互联网!
【8月更文挑战第18天】Docker容器内网络不通是开发者常遇问题,可能因网络配置错、Docker服务异常或防火墙阻碍等原因引起。本文提供六种解决策略:确认Docker服务运行状态、重启Docker服务、检查与自定义Docker网络设置、验证宿主机网络连接、临时禁用宿主机IPv6及检查防火墙规则。通过这些步骤,多数网络问题可得以解决,确保容器正常联网。
7 1
|
3天前
|
安全 Ubuntu Docker
深度挖掘Docker 容器
【8月更文挑战第16天】Docker容器间的连接是容器化技术的关键,支持容器与宿主机的数据交换。主要方法包括:1) 利用Docker网络驱动创建自定义网络,使容器相连通信;2) 采用Docker Compose通过配置文件简化多容器应用的部署与互联;3) 虽不推荐,早期使用--link参数实现容器互联;4) 通过环境变量配置连接信息;5) 共享卷支持文件共享和间接通信。推荐使用Docker网络和Docker Compose以实现高效灵活的容器间通信。
13 3
|
3天前
|
Ubuntu Linux Docker
使用Docker进行容器化:从零开始的技术博文
【8月更文挑战第16天】从零开始掌握Docker容器化技术:本文详细介绍Docker基本概念、安装配置流程及核心组件。涵盖Docker镜像与容器管理、镜像加速配置,以及如何利用Dockerfile自动化构建镜像,助您快速入门并高效运用Docker进行软件开发与部署。
|
4天前
|
Java Nacos Docker
"揭秘!Docker部署Seata遇上Nacos,注册成功却报错?这些坑你不得不防!一网打尽解决秘籍,让你的分布式事务稳如老狗!"
【8月更文挑战第15天】在微服务架构中,Nacos搭配Seata确保数据一致性时,Docker部署Seata后可能出现客户端连接错误,如“can not connect to services-server”。此问题多由网络配置不当、配置文件错误或版本不兼容引起。解决策略包括:调整Docker网络设置确保可达性;检查并修正`file.conf`和`registry.conf`中的Nacos地址和端口;验证Seata与Nacos版本兼容性;修改配置后重启服务;参考官方文档和最佳实践进行配置。通过这些步骤,能有效排除故障,保障服务稳定运行。
13 0
|
4天前
|
Docker 容器
Docker - 网络模式与容器网络互连
Docker的网络模式包括桥接模式、主机模式和覆盖网络模式,以及如何通过Docker的网络操作命令实现容器网络互连。
9 0
|
4天前
|
Linux Docker 容器
在CentOS操作系统上使用yum安装/使用/卸载Docker容器引擎
在CentOS操作系统上安装、配置、使用和卸载Docker容器引擎的详细步骤,包括配置Docker镜像加速的方法。
24 0
|
4天前
|
存储 Ubuntu Linux
如何在 Ubuntu 上使用 Docker 容器化和部署多个 WordPress 应用程序
如何在 Ubuntu 上使用 Docker 容器化和部署多个 WordPress 应用程序
11 0