1.拉最新 tomcat 8?
docker pull tomcat:8
2.查看本地 镜像
?3.挂载语法
docker run --name mytomcat8 -p 8888:8080 -v ~/soft/apache-tomcat-8.5.68/webapps:/usr/local/tomcat/webapps/ -d tomcat:8
多目录挂载 只需多个 -v 连接即可 如下代码示例 映射 webapps、conf、logs 三个文件夹 :
ufo@UPC:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat 8 ecd199dd86fe 42 hours ago 533MB
nginx latest 4cdc5dd7eaad 3 days ago 133MB
ufo@UPC:~$ docker run -d --name dk_tomcat8 -p 8888:8080 -v ~/soft/apache-tomcat-8.5.69/conf/:/usr/local/tomcat/conf/ -v ~/soft/apache-tomcat-8.5.69/logs/:/usr/local/tomcat/logs/ -v ~/soft/apache-tomcat-8.5.69/webapps/:/usr/local/tomcat/webapps/ ecd199dd86fe
94942783d42efbc622a03021540a0d2ed7814eb9e9bad47383adfcdf90e0a1e5
ufo@UPC:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
94942783d42e ecd199dd86fe "catalina.sh run" 6 seconds ago Up 4 seconds 0.0.0.0:8888->8080/tcp, :::8888->8080/tcp dk_tomcat8
war包、配置文件、在宿主机器上目录更新的同时 docker 容器内的文件内容也跟着改变,日志也会从docker容器logs文件夹同步到宿主机器logs下。
?4.测试
?--------------------------------------------------------------------------------------------------------------------------------
?PS:如果访问 404?
docker exec -it 【实例ID】 /bin/bash
?执行
mv webapps webapps_bak
mv webapps webapps.dist webapps
Ctrl+P+Q:
docker restart xx
‘‘OK’’!
|