拉取镜像
docker pull tomcat
启动镜像
docker run -p 8081:8080 --name tomcat -d tomcat
参数说明:
run run 是运行一个容器
-d 表示后台运行
-p 表示容器内部端口和服务器端口映射关联
–name 添加容器名字
查看启动镜像
docker ps
特别注意,如果我们直接访问8081端口会报错。
因为pull下来的tomcat镜像webapps下没有东西
交互式进入容器
docker exec -it 9646988bf846 /bin/bash
参数说明:
docker exec 执行的容器
-it 交互式的
9646988bf846 容器id
bash 进入
执行命令
1.复制webapps.dist文件夹下的所有目录到webapps中
cp -r webapps.dist/* webapps
2.进入webapps/Root目录中
cd webapps/Root
3.添加hello world
echo hello world >>index.jsp
退出容器
exit
浏览器访问
http://192.168.158.128:8081/