前言:

        Docker容器的安装:https://blog.csdn.net/qq_37896194/article/details/83277072

步骤:

1、启动Tomcat,命名为myTomcat

[root@localhost ~]# docker run -d  --name myTomcat -p 8088:8080 tomcat
cecb37db8134f1b1fe6d13c43b0b22d1832a9937b9d2bbfa9958eb180bd81eb6

2、上传war包至Linux主机(本人上传至home文件夹下)

[root@localhost ~]# cd /home
[root@localhost home]# ls
ssm.war

3、查看myTomcat的ID(cecb37db8134)

[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
cecb37db8134        tomcat              "catalina.sh run"        9 minutes ago       Up 9 minutes        0.0.0.0:9999->8080/tcp              myTomcat
1226f307b5ba        tomcat              "catalina.sh run"        About an hour ago   Up 28 minutes       0.0.0.0:8888->8080/tcp              agitated_leavitt
ec9d0d788590        mysql               "docker-entrypoint.s…"   16 hours ago        Up 16 hours         0.0.0.0:3306->3306/tcp, 33060/tcp   mysql02

4、进入该Tomcat容器中,然后退出(与Tomcat容器进行交互)

[root@localhost ~]# sudo docker exec -it cecb37db8134 /bin/bash
root@cecb37db8134:/usr/local/tomcat# ls
BUILDING.txt     LICENSE  README.md      RUNNING.txt  conf     lib   native-jni-lib  webapps
CONTRIBUTING.md  NOTICE   RELEASE-NOTES  bin          include  logs  temp            work
root@cecb37db8134:/usr/local/tomcat# 
root@cecb37db8134:/usr/local/tomcat# exit

5、复制war包到Tomcat的webapps目录下

[root@localhost ~]# docker cp /home/qrcode.war cecb37db8134:/usr/local/tomcat/webapps

6、重新进入容器,发现ssm.war已经在webapps目录下了

[root@localhost ~]# sudo docker exec -it cecb37db8134 /bin/bash
root@cecb37db8134:/usr/local/tomcat# ls ./webapps/
ROOT  docs  examples  host-manager  manager  ssm  ssm.war
root@cecb37db8134:/usr/local/tomcat# 

7、重启docker容器,访问url即可

[root@localhost ~]# docker restart cecb37db8134
cecb37db8134

附录:

  • 常用的docker命令

//1、通过镜像产生一个容器
docker run -p port1:port2 containerName:tag
//2、启动一个已有的容器
docker start containerID/containerName
//3、停止一个容器
docker stop containerID/containerName
//4、重启一个容器
docker restart containerID/containerName
//5、与一个已经启动的容器进行交互式操作
语法:docker exec -it containnerID/containerName /bin/bash
例子:docker exec -it cecb37db8134 /bin/bash
//6、复制文件到容器中
语法:docker cp src_path containerID:dest_path
例子:docker cp /home/a.txt cecb37db8134:/usr/local/tomcat/

 

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐