搜索tomcat版本
docker search tomcat
![在这里插入图片描述 在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/20210326122449899.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0Jlcl9CYWk=,size_16,color_FFFFFF,t_70&x-oss-process=image/resize,w_1400/format,webp)
拉取tomcat镜像
docker pull tomcat
![在这里插入图片描述 在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/20210326122549938.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0Jlcl9CYWk=,size_16,color_FFFFFF,t_70&x-oss-process=image/resize,w_1400/format,webp)
启动 拷贝配置文件
# 创建Tomcat文件夹
mkdir -p ~/i/apps/tomcat/{conf,logs,webapps}
# 启动 Tomcat
docker run -d -p 8080:8080 --name tomcat-test tomcat
# 拷贝 Tomcat 配置文件
docker cp tomcat-test:/usr/local/tomcat/conf/* ~/i/apps/tomcat/conf
docker cp tomcat-test:/usr/local/tomcat/logs/* ~/i/apps/tomcat/logs
# 关闭 删除Tomcat
docker stop tomcat-test
docker rm tomcat-test
创建启动脚本
cd ~/i/apps/tomcat/
cat <<EOF > start.sh
#!/bin/bash
TOMCAT_DIR=`pwd`
docker stop mytomcat
docker rm mytomcat
docker run -d --restart always -p 8080:8080 --name mytomcat -v \${TOMCAT_DIR}/html:/usr/share/nginx/html -v \${TOMCAT_DIR}/webapps:/usr/local/tomcat/webapps -v \${TOMCAT_DIR}/conf:/usr/local/tomcat/conf -v \${TOMCAT_DIR}/logs:/usr/local/tomcat/logs tomcat
EOF