Docker容器化部署实战:Tomcat与Nginx服务配置指南

部署Tomcat

搜索镜像

使用以下命令搜索可用的Tomcat镜像:

bash 复制代码
docker search tomcat

拉取镜像

拉取官方Tomcat镜像:

bash 复制代码
docker pull tomcat

创建专用目录

为Tomcat配置和数据创建专用目录:

bash 复制代码
mkdir tomcat

运行临时容器并复制配置文件

启动临时容器以复制配置文件:

bash 复制代码
docker run --name temp -itd tomcat
docker cp temp:/usr/local/tomcat/conf ./tomcat
docker rm -f temp

运行正式容器

挂载配置文件并启动正式容器:

bash 复制代码
docker run --name mytomcat -itd \
-p 8080:8080 \
-v /root/tomcat/conf:/usr/local/tomcat/conf \
-v /root/tomcat/webapps:/usr/local/tomcat/webapps \
tomcat

部署Nginx

搜索镜像

搜索可用的Nginx镜像:

bash 复制代码
docker search nginx

拉取镜像

拉取官方Nginx镜像:

bash 复制代码
docker pull nginx

创建专用目录

为Nginx配置和数据创建专用目录:

bash 复制代码
mkdir nginx

运行临时容器并复制配置文件

启动临时容器以复制配置文件:

bash 复制代码
docker run --name temp -itd nginx
docker cp temp:/etc/nginx/nginx.conf ./nginx/nginx.conf
docker cp temp:/etc/nginx/conf.d ./nginx/
docker cp temp:/usr/share/nginx/html ./nginx/
docker rm -f temp

运行正式容器

挂载配置文件并启动正式容器:

bash 复制代码
docker run --name mynginx -itd \
-p 80:80 \
-v /root/nginx/conf.d:/etc/nginx/conf.d \
-v /root/nginx/html:/usr/share/nginx/html/ \
-v /root/nginx/nginx.conf:/etc/nginx/nginx.conf \
nginx
相关推荐
闲云一鹤21 小时前
nginx 快速入门教程 - 写给前端的你
前端·nginx·前端工程化
小p2 天前
docker学习7:docker 容器的通信方式
docker
小p2 天前
docker学习5:提升Dockerfile水平的5个技巧
docker
小p2 天前
docker学习3:docker是怎么实现的?
docker
小p3 天前
docker学习: 2. 构建镜像Dockerfile
docker
小p4 天前
docker学习: 1. docker基本使用
docker
崔小汤呀4 天前
Docker部署Nacos
docker·容器
缓解AI焦虑4 天前
Docker + K8s 部署大模型推理服务:资源划分与多实例调度
docker·容器
何中应4 天前
Nginx转发请求错误
前端·后端·nginx