Dockerfile构建Tomcat基础镜像
作者:互联网
1、安装docker并修改阿里云仓库地址,并重启
yum -y install docker
service enabled docker
vim /etc/docker/daemon.json
{
"registry-mirrors": ["https://mj9kvemk.mirror.aliyuncs.com"]
}
service restart docker
2、修改/etc/yum.repos.d/CentOS-Base.repo不校验签名
sed -i 's/gpgcheck=1/gpgcheck=0/g' /etc/yum.repos.d/*
yum makecache fast
yum repolist
3、编写Dockerfile
cd /home
[root@VM-0-17-centos home]# cat Dockerfile
FROM centos:7
MAINTAINER wangmiao
ENV VERSION=8.5.39
ENV JAVA_HOME /usr/local/jdk
RUN yum install wget -y
RUN wget http://archive.apache.org/dist/tomcat/tomcat-8/v${VERSION}/bin/apache-tomcat-${VERSION}.tar.gz && \
tar zxf apache-tomcat-${VERSION}.tar.gz && \
mv apache-tomcat-${VERSION} /usr/local/tomcat && \
rm -rf apache-tomcat-${VERSION}.tar.gz /usr/local/tomcat/webapps/*
EXPOSE 8080
CMD ["catalina.sh", "run"]
docker build -t tomcat-8.5.39:v1 .
4、构建镜像
[root@VM-0-17-centos home]# docker build -t tomcat-8.5.39:v1 .
Sending build context to Docker daemon 2.048kB
Step 1/8 : FROM centos:7
---> 8652b9f0cb4c
Step 2/8 : MAINTAINER wangmiao
---> Running in c4c696059150
Removing intermediate container c4c696059150
---> af4d67e11f3d
Step 3/8 : ENV VERSION=8.5.39
---> Running in f3d124f3b658
Removing intermediate container f3d124f3b658
---> d0d81031b624
Step 4/8 : ENV JAVA_HOME /usr/local/jdk
---> Running in a862917f3386
Removing intermediate container a862917f3386
---> fa46e96b5e90
Step 5/8 : RUN yum install wget -y
---> Running in eff3529f3235
Loaded plugins: fastestmirror, ovl
Determining fastest mirrors
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package wget.x86_64 0:1.14-18.el7_6.1 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
wget x86_64 1.14-18.el7_6.1 base 547 k
Transaction Summary
================================================================================
Install 1 Package
Total download size: 547 k
Installed size: 2.0 M
Downloading packages:
warning: /var/cache/yum/x86_64/7/base/packages/wget-1.14-18.el7_6.1.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for wget-1.14-18.el7_6.1.x86_64.rpm is not installed
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
Userid : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
Package : centos-release-7-9.2009.0.el7.centos.x86_64 (@CentOS)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : wget-1.14-18.el7_6.1.x86_64 1/1
install-info: No such file or directory for /usr/share/info/wget.info.gz
Verifying : wget-1.14-18.el7_6.1.x86_64 1/1
Installed:
wget.x86_64 0:1.14-18.el7_6.1
Complete!
Removing intermediate container eff3529f3235
---> 3d210d3967bd
Step 6/8 : RUN wget http://archive.apache.org/dist/tomcat/tomcat-8/v${VERSION}/bin/apache-tomcat-${VERSION}.tar.gz && tar zxf apache-tomcat-${VERSION}.tar.gz && mv apache-tomcat-${VERSION} /usr/local/tomcat && rm -rf apache-tomcat-${VERSION}.tar.gz /usr/local/tomcat/webapps/*
---> Running in c27c8446913d
--2021-05-18 16:40:29-- http://archive.apache.org/dist/tomcat/tomcat-8/v8.5.39/bin/apache-tomcat-8.5.39.tar.gz
Resolving archive.apache.org (archive.apache.org)... 138.201.131.134, 2a01:4f8:172:2ec5::2
Connecting to archive.apache.org (archive.apache.org)|138.201.131.134|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9672485 (9.2M) [application/x-gzip]
Saving to: 'apache-tomcat-8.5.39.tar.gz'
0K .......... .......... .......... .......... .......... 0% 63.6K 2m28s
50K .......... .......... .......... .......... .......... 1% 35.0K 3m27s
100K .......... .......... .......... .......... .......... 1% 12.8K 6m20s
150K .......... .......... .......... .......... .......... 2% 13.8K 7m31s
200K .......... .......... .......... .......... .......... 2% 14.1K 8m9s
250K .......... .......... .......... .......... .......... 3% 18.3K 8m9s
300K .......... .......... .......... .......... .......... 3% 19.2K 8m4s
350K .......... .......... .......... .......... .......... 4% 10.5K 8m49s
400K .......... .......... .......... .......... .......... 4% 18.2K 8m42s
450K .......... .......... .......... .......... .......... 5% 24.0K 8m25s
500K .......... .......... .......... .......... .......... 5% 16.0K 8m27s
550K .......... .......... .......... .......... .......... 6% 12.7K 8m40s
600K .......... .......... .......... .......... .......... 6% 17.5K 8m36s
650K .......... .......... .......... .......... .......... 7% 26.2K 8m20s
700K .......... .......... .......... .......... .......... 7% 27.6K 8m5s
750K .......... .......... .......... .......... .......... 8% 10.5K 8m24s
800K .......... .......... .......... .......... .......... 8% 16.0K 8m23s
850K .......... .......... .......... .......... .......... 9% 11.7K 8m33s
900K .......... .......... .......... .......... .......... 10% 15.1K 8m32s
950K .......... .......... .......... .......... .......... 10% 27.5K 8m19s
1000K .......... .......... .......... .......... .......... 11% 19.6K 8m13s
1050K .......... .......... .......... .......... .......... 11% 12.2K 8m19s
1100K .......... .......... .......... .......... .......... 12% 15.4K 8m18s
1150K .......... .......... .......... .......... .......... 12% 18.2K 8m13s
1200K .......... .......... .......... .......... .......... 13% 13.2K 8m15s
1250K .......... .......... .......... .......... .......... 13% 34.4K 8m2s
1300K .......... .......... .......... .......... .......... 14% 28.0K 7m52s
1350K .......... .......... .......... .......... .......... 14% 15.8K 7m51s
1400K .......... .......... .......... .......... .......... 15% 4.90K 8m28s
1450K .......... .......... .......... .......... .......... 15% 3.64K 9m21s
1500K .......... .......... .......... .......... .......... 16% 5.39K 9m47s
1550K .......... .......... .......... .......... .......... 16% 16.6K 9m39s
1600K .......... .......... .......... .......... .......... 17% 13.4K 9m36s
1650K .......... .......... .......... .......... .......... 17% 13.7K 9m32s
1700K .......... .......... .......... .......... .......... 18% 7.47K 9m42s
1750K .......... .......... .......... .......... .......... 19% 18.7K 9m33s
1800K .......... .......... .......... .......... .......... 19% 13.8K 9m29s
1850K .......... .......... .......... .......... .......... 20% 13.6K 9m25s
1900K .......... .......... .......... .......... .......... 20% 17.9K 9m17s
1950K .......... .......... .......... .......... .......... 21% 25.5K 9m7s
2000K .......... .......... .......... .......... .......... 21% 12.6K 9m5s
2050K .......... .......... .......... .......... .......... 22% 18.6K 8m57s
2100K .......... .......... .......... .......... .......... 22% 9.57K 8m59s
2150K .......... .......... .......... .......... .......... 23% 15.4K 8m54s
2200K .......... .......... .......... .......... .......... 23% 9.13K 8m56s
2250K .......... .......... .......... .......... .......... 24% 20.5K 8m48s
2300K .......... .......... .......... .......... .......... 24% 19.0K 8m41s
2350K .......... .......... .......... .......... .......... 25% 28.4K 8m32s
2400K .......... .......... .......... .......... .......... 25% 23.2K 8m24s
2450K .......... .......... .......... .......... .......... 26% 16.7K 8m19s
2500K .......... .......... .......... .......... .......... 26% 18.9K 8m13s
2550K .......... .......... .......... .......... .......... 27% 16.7K 8m8s
2600K .......... .......... .......... .......... .......... 28% 23.2K 8m0s
2650K .......... .......... .......... .......... .......... 28% 9.35K 8m1s
2700K .......... .......... .......... .......... .......... 29% 20.9K 7m55s
2750K .......... .......... .......... .......... .......... 29% 17.7K 7m50s
2800K .......... .......... .......... .......... .......... 30% 16.9K 7m45s
2850K .......... .......... .......... .......... .......... 30% 24.9K 7m38s
2900K .......... .......... .......... .......... .......... 31% 16.7K 7m33s
2950K .......... .......... .......... .......... .......... 31% 15.7K 7m29s
3000K .......... .......... .......... .......... .......... 32% 19.6K 7m24s
3050K .......... .......... .......... .......... .......... 32% 22.4K 7m18s
3100K .......... .......... .......... .......... .......... 33% 8.75K 7m19s
3150K .......... .......... .......... .......... .......... 33% 14.9K 7m15s
3200K .......... .......... .......... .......... .......... 34% 31.3K 7m8s
3250K .......... .......... .......... .......... .......... 34% 20.0K 7m3s
3300K .......... .......... .......... .......... .......... 35% 11.0K 7m1s
3350K .......... .......... .......... .......... .......... 35% 19.1K 6m56s
3400K .......... .......... .......... .......... .......... 36% 15.0K 6m53s
3450K .......... .......... .......... .......... .......... 37% 14.2K 6m49s
3500K .......... .......... .......... .......... .......... 37% 17.5K 6m45s
3550K .......... .......... .......... .......... .......... 38% 10.0K 6m44s
3600K .......... .......... .......... .......... .......... 38% 19.6K 6m39s
3650K .......... .......... .......... .......... .......... 39% 22.4K 6m34s
3700K .......... .......... .......... .......... .......... 39% 26.8K 6m28s
3750K .......... .......... .......... .......... .......... 40% 21.3K 6m23s
3800K .......... .......... .......... .......... .......... 40% 24.9K 6m18s
3850K .......... .......... .......... .......... .......... 41% 19.2K 6m13s
3900K .......... .......... .......... .......... .......... 41% 19.7K 6m9s
3950K .......... .......... .......... .......... .......... 42% 18.2K 6m5s
4000K .......... .......... .......... .......... .......... 42% 9.93K 6m3s
4050K .......... .......... .......... .......... .......... 43% 13.9K 6m0s
4100K .......... .......... .......... .......... .......... 43% 9.61K 5m59s
4150K .......... .......... .......... .......... .......... 44% 13.3K 5m56s
4200K .......... .......... .......... .......... .......... 44% 15.1K 5m53s
4250K .......... .......... .......... .......... .......... 45% 8.91K 5m52s
4300K .......... .......... .......... .......... .......... 46% 13.9K 5m49s
4350K .......... .......... .......... .......... .......... 46% 20.7K 5m44s
4400K .......... .......... .......... .......... .......... 47% 22.8K 5m40s
4450K .......... .......... .......... .......... .......... 47% 31.8K 5m34s
4500K .......... .......... .......... .......... .......... 48% 31.2K 5m29s
4550K .......... .......... .......... .......... .......... 48% 15.8K 5m25s
4600K .......... .......... .......... .......... .......... 49% 14.2K 5m22s
4650K .......... .......... .......... .......... .......... 49% 12.4K 5m19s
4700K .......... .......... .......... .......... .......... 50% 14.3K 5m16s
4750K .......... .......... .......... .......... .......... 50% 28.5K 5m11s
4800K .......... .......... .......... .......... .......... 51% 31.3K 5m6s
4850K .......... .......... .......... .......... .......... 51% 17.4K 5m3s
4900K .......... .......... .......... .......... .......... 52% 6.00K 5m4s
4950K .......... .......... .......... .......... .......... 52% 30.6K 4m59s
5000K .......... .......... .......... .......... .......... 53% 16.5K 4m55s
5050K .......... .......... .......... .......... .......... 53% 16.5K 4m52s
5100K .......... .......... .......... .......... .......... 54% 17.3K 4m48s
5150K .......... .......... .......... .......... .......... 55% 20.5K 4m44s
5200K .......... .......... .......... .......... .......... 55% 16.6K 4m40s
5250K .......... .......... .......... .......... .......... 56% 16.2K 4m37s
5300K .......... .......... .......... .......... .......... 56% 11.1K 4m34s
5350K .......... .......... .......... .......... .......... 57% 19.6K 4m30s
5400K .......... .......... .......... .......... .......... 57% 6.70K 4m30s
5450K .......... .......... .......... .......... .......... 58% 4.91K 4m31s
5500K .......... .......... .......... .......... .......... 58% 4.68K 4m33s
5550K .......... .......... .......... .......... .......... 59% 8.67K 4m31s
5600K .......... .......... .......... .......... .......... 59% 25.5K 4m26s
5650K .......... .......... .......... .......... .......... 60% 36.4K 4m22s
5700K .......... .......... .......... .......... .......... 60% 20.4K 4m17s
5750K .......... .......... .......... .......... .......... 61% 20.7K 4m13s
5800K .......... .......... .......... .......... .......... 61% 24.5K 4m9s
5850K .......... .......... .......... .......... .......... 62% 14.8K 4m5s
5900K .......... .......... .......... .......... .......... 62% 28.2K 4m1s
5950K .......... .......... .......... .......... .......... 63% 19.3K 3m57s
6000K .......... .......... .......... .......... .......... 64% 26.4K 3m53s
6050K .......... .......... .......... .......... .......... 64% 19.4K 3m49s
6100K .......... .......... .......... .......... .......... 65% 13.6K 3m46s
6150K .......... .......... .......... .......... .......... 65% 14.4K 3m42s
6200K .......... .......... .......... .......... .......... 66% 17.5K 3m38s
6250K .......... .......... .......... .......... .......... 66% 14.9K 3m35s
6300K .......... .......... .......... .......... .......... 67% 11.5K 3m32s
6350K .......... .......... .......... .......... .......... 67% 34.0K 3m28s
6400K .......... .......... .......... .......... .......... 68% 19.1K 3m24s
6450K .......... .......... .......... .......... .......... 68% 21.3K 3m20s
6500K .......... .......... .......... .......... .......... 69% 25.5K 3m16s
6550K .......... .......... .......... .......... .......... 69% 22.9K 3m12s
6600K .......... .......... .......... .......... .......... 70% 14.1K 3m9s
6650K .......... .......... .......... .......... .......... 70% 13.2K 3m6s
6700K .......... .......... .......... .......... .......... 71% 17.0K 3m2s
6750K .......... .......... .......... .......... .......... 71% 12.9K 2m59s
6800K .......... .......... .......... .......... .......... 72% 16.5K 2m55s
6850K .......... .......... .......... .......... .......... 73% 20.6K 2m52s
6900K .......... .......... .......... .......... .......... 73% 15.6K 2m48s
6950K .......... .......... .......... .......... .......... 74% 16.9K 2m45s
7000K .......... .......... .......... .......... .......... 74% 20.6K 2m41s
7050K .......... .......... .......... .......... .......... 75% 14.8K 2m38s
7100K .......... .......... .......... .......... .......... 75% 9.93K 2m35s
7150K .......... .......... .......... .......... .......... 76% 31.6K 2m31s
7200K .......... .......... .......... .......... .......... 76% 34.8K 2m27s
7250K .......... .......... .......... .......... .......... 77% 14.6K 2m24s
7300K .......... .......... .......... .......... .......... 77% 12.4K 2m20s
7350K .......... .......... .......... .......... .......... 78% 12.3K 2m17s
7400K .......... .......... .......... .......... .......... 78% 12.3K 2m14s
7450K .......... .......... .......... .......... .......... 79% 12.8K 2m11s
7500K .......... .......... .......... .......... .......... 79% 19.5K 2m7s
7550K .......... .......... .......... .......... .......... 80% 35.1K 2m4s
7600K .......... .......... .......... .......... .......... 80% 13.9K 2m0s
7650K .......... .......... .......... .......... .......... 81% 20.5K 1m57s
7700K .......... .......... .......... .......... .......... 82% 11.9K 1m54s
7750K .......... .......... .......... .......... .......... 82% 8.28K 1m51s
7800K .......... .......... .......... .......... .......... 83% 13.8K 1m47s
7850K .......... .......... .......... .......... .......... 83% 16.5K 1m44s
7900K .......... .......... .......... .......... .......... 84% 21.7K 1m40s
7950K .......... .......... .......... .......... .......... 84% 22.5K 97s
8000K .......... .......... .......... .......... .......... 85% 11.5K 94s
8050K .......... .......... .......... .......... .......... 85% 41.9K 90s
8100K .......... .......... .......... .......... .......... 86% 19.1K 87s
8150K .......... .......... .......... .......... .......... 86% 10.0K 83s
8200K .......... .......... .......... .......... .......... 87% 11.2K 80s
8250K .......... .......... .......... .......... .......... 87% 22.7K 77s
8300K .......... .......... .......... .......... .......... 88% 10.6K 74s
8350K .......... .......... .......... .......... .......... 88% 25.2K 70s
8400K .......... .......... .......... .......... .......... 89% 13.9K 67s
8450K .......... .......... .......... .......... .......... 89% 12.1K 63s
8500K .......... .......... .......... .......... .......... 90% 10.6K 60s
8550K .......... .......... .......... .......... .......... 91% 20.6K 57s
8600K .......... .......... .......... .......... .......... 91% 23.2K 53s
8650K .......... .......... .......... .......... .......... 92% 18.1K 50s
8700K .......... .......... .......... .......... .......... 92% 10.2K 47s
8750K .......... .......... .......... .......... .......... 93% 24.7K 43s
8800K .......... .......... .......... .......... .......... 93% 20.6K 40s
8850K .......... .......... .......... .......... .......... 94% 14.6K 36s
8900K .......... .......... .......... .......... .......... 94% 17.6K 33s
8950K .......... .......... .......... .......... .......... 95% 10.2K 30s
9000K .......... .......... .......... .......... .......... 95% 21.2K 26s
9050K .......... .......... .......... .......... .......... 96% 17.3K 23s
9100K .......... .......... .......... .......... .......... 96% 8.00K 20s
9150K .......... .......... .......... .......... .......... 97% 15.2K 17s
9200K .......... .......... .......... .......... .......... 97% 12.0K 13s
9250K .......... .......... .......... .......... .......... 98% 15.0K 10s
9300K .......... .......... .......... .......... .......... 98% 11.9K 6s
9350K .......... .......... .......... .......... .......... 99% 15.2K 3s
9400K .......... .......... .......... .......... ..... 100% 18.2K=10m35s
2021-05-18 16:51:05 (14.9 KB/s) - 'apache-tomcat-8.5.39.tar.gz' saved [9672485/9672485]
Removing intermediate container c27c8446913d
---> 4861464041d5
Step 7/8 : EXPOSE 8080
---> Running in 7be2ad1fb6ee
Removing intermediate container 7be2ad1fb6ee
---> 22473080e2e7
Step 8/8 : CMD ["catalina.sh", "run"]
---> Running in 77417e90125d
Removing intermediate container 77417e90125d
---> 5cf4fa7303ad
Successfully built 5cf4fa7303ad
Successfully tagged tomcat-8.5.39:v1
[root@VM-0-17-centos home]#
5、查看构建后的镜像
[root@VM-0-17-centos home]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat-8.5.39 v1 5cf4fa7303ad 3 minutes ago 330MB
6、把镜像保存到本地文件
docker save tomcat-8.5.39:v1 -o tomcat-8.5.39.tar
标签:39,Tomcat,tomcat,---,VERSION,apache,镜像,Dockerfile,.......... 来源: https://www.cnblogs.com/xjzyy/p/14783434.html