使用公共tomcat鏡像構建,
一、確保已經啓動了dockers服務web
[root@localhost ~]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: active (running) since Sun 2019-08-11 11:23:20 CST; 21h ago
Docs: http://docs.docker.com
Main PID: 26466 (dockerd-current)
...docker
二、從公共倉庫下載tomcat鏡像瀏覽器
[root@localhost ~]# docker search tomcat -->查看公共倉庫內鏡像
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker.io docker.io/tomcat Apache Tomcat is an open source implementa... 2491 [OK]
docker.io docker.io/tomee Apache TomEE is an all-Apache Java EE cert... 66 [OK]
docker.io docker.io/dordoka/tomcat Ubuntu 14.04, Oracle JDK 8 and Tomcat 8 ba... 53 [OK]
docker.io docker.io/bitnami/tomcat Bitnami Tomcat Docker Image 29 [OK]tomcat[root@localhost ~]# docker pull tomcat -->我以前已經下載好了
Using default tag: latest
Trying to pull repository docker.io/library/tomcat ...
latest: Pulling from docker.io/library/tomcat
Digest: sha256:2785fac92d1bcd69d98f2461c6799390555a41fd50d3f847b544368d594c637b
Status: Image is up to date for docker.io/tomcat:latestbash[root@localhost ~]# docker images -->查看本地鏡像
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/tomcat latest 238e6d7313e3 3 weeks ago 506 MBapp
三、運行容器webapp
[root@localhost test]# pwd
/data/test
[root@localhost test]# docker run --name mytomcat -p 8080:8080 -v $PWD/test:/usr/local/tomcat/webapps/test -d tomcat
注:
--name 容器的名稱
-p 端口映射,將容器的8080端口映射到當前主機的8080端口上
-v 掛載目錄 $PWD當前目錄 將容器的test目錄掛載到本地的$PWD/test上
-d 指定鏡像
35468d20e2b0f16ed05153eb0ecbcb26615446e04c6cae76dd68e3c669454249
[root@localhost test]# docker ps -->名爲mytomcat的容器已經啓動
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
35468d20e2b0 tomcat "catalina.sh run" 6 seconds ago Up 6 seconds 0.0.0.0:8080->8080/tcp mytomcat
請求瀏覽器訪問
tcp
四、維護ide
[root@localhost ~]# docker cp test/adveranaly.war d4b3b0382a72 :/usr/local/tomcat/webapps --> 上傳war包
[root@localhost ~]# docker exec -it mytomcat /bin/bash -->查看容器內的war包
root@d4b3b0382a72:/usr/local/tomcat#
root@d4b3b0382a72:/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@d4b3b0382a72:/usr/local/tomcat# cd webapps/
root@d4b3b0382a72:/usr/local/tomcat/webapps# ls
adveranaly.war
[root@localhost ~]# docker restart mytomcat -->重啓容器
[root@localhost ~]# docker exec -it mytomcat /bin/bash
root@d4b3b0382a72:/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@d4b3b0382a72:/usr/local/tomcat# cd webapps/
root@d4b3b0382a72:/usr/local/tomcat/webapps# ls -->確認已經執行
ROOT adveranaly adveranaly.warrest