Docker安装Tomcat应用服务器
1、安装镜像
1. Install the image:
可以先到https://hub.docker.com/ 搜索镜像
You can get there first. https://hub.docker.com/ search mirror
或使用docker search 镜像名称
or use docker search image name
docker pull tomcat
2、查看验证下载好的镜像
docker images
3、启动tomcat
3. Start tomcat2. Check and verify the downloaded image.
-p : 8080 in front is the port of this machine, 8080 after the colon is the port of docker container, and tomcat is 8080 by default.
-d:后台运行
-i 启动这个容器
-t 容器创建成功后我们可以进入到容器中
-d: Run in background
--name : 是给容器起一个别名,方便使用,不然docker会默认给容器一个随机字符串的名称
--name : is to give an alias to the container for easy use, otherwise docker will give the container a random string name by default
-v 用来指定目录映射 --指定宿主机的某一个目录和容器中的某一个目录的对应关系
-p 用来指定端口映射 --指定宿主机的某一端口和容器中运行软件端口的对应关系:例如前边的8080是linux本机的端口,冒号后面的8080是docker容器的端口,tomcat默认是8080
-v: file mount path (not used in the above command)
docker run -it -d --name tomcat
-v /var/lib/docker/volumes/tomcat:/usr/local/tomcat/webapps
-v /var/lib/docker/volumes/tomcat:/usr/local/tomcat/logs
-v /usr/local/tomcat/conf:/usr/local/tomcat/conf -p 8080:8080 tomcat
4、查看tomcat安装位置
View tomcat installation location
docker exec -it tomcat /bin/bash
如果想得到容器更为详细信息,例如。挂载目录、tomcat版本等
(2) sudo docker inspect -f {{.State.Pid}} 44fc0f0582d9(2), and then get the full ID according to either of these two items.
docker inspect 容器ID
5、高版本的tomcat,默认把webapps下的测试应用移动到了webapps.dist
(3) Copy the file from the local to the docker container
cp -rf /usr/local/tomcat/webapps.dist/ROOT /usr/local/tomcat/webapps/ROOT
6、访问测试
原文出处【开源吧】:https://www.ossbar.com/#/platformConsultingDetails?newsId=186