Docker定制tomcat镜像

下载centos镜像、Tomcat包和jdk包

[root@localhost dockerfile]docker pull centos
[root@localhost dockerfile]wget https://dlcdn.apache.org/tomcat/tomcat-10/v10.1.0-M8/bin/apache-tomcat-10.1.0-M8.tar.gz && wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.rpm

下载的tomcat安装包和jdk包都需要放到Dockfile文件所在的目录,否则build会报错

创建和定制Dockerfile

[root@localhost dockerfile]touch Dockerfile

[root@localhost dockerfile]vim Doclerfile

FROM centos

MAINTAINER kingbywork<games360@126.com>

COPY jdk-17_linux-x64_bin.rpm /opt/

RUN yum -y install opt/jdk-17_linux-x64_bin.rpm



ADD apache-tomcat-10.1.0-M8.tar.gz /usr/local/

RUN mv /usr/local/apache-tomcat-10.1.0-M8 /usr/local/tomcat10

ENV CATALINA_HOME /usr/local/tomcat10

WORKDIR /usr/local/

EXPOSE 8080

CMD /usr/local/tomcat10/bin/startup.sh && tail -f 10 /usr/local/tomcat10/logs/catalina.out

生成镜像

[root@localhost dockerfile]# docker build -t tomcat10:v1.0 .

Sending build context to Docker daemon 2.048kB

Step 1/10 : FROM centos

---> 5d0da3dc9764

Step 2/10 : MAINTAINER kingbywork

---> Using cache

---> 8afd52cfdbf6

Step 3/10 : COPY jdk-17_linux-x64_bin.rpm /usr/local/

---> 9f028d1fd7fa

Step 4/10 : RUN yum -y install /opt/jdk-17_linux-x64_bin.rpm

---> Running in ced0bdf80a92

CentOS Linux 8 - AppStream 335 kB/s | 8.4 MB 00:25

CentOS Linux 8 - BaseOS 318 kB/s | 4.6 MB 00:14

CentOS Linux 8 - Extras 6.1 kB/s | 10 kB 00:01

Last metadata expiration check: 0:00:01 ago on Tue Jan 11 12:50:06 2022.

Dependencies resolved.

================================================================================

Package Architecture Version Repository Size

================================================================================

Installing:

jdk-17 x86_64 2000:17.0.1-ga @commandline 155 M

Transaction Summary

================================================================================

Install 1 Package

Total size: 155 M

Installed size: 301 M

Downloading Packages:

Running transaction check

Transaction check succeeded.

Running transaction test

Transaction test succeeded.

Running transaction

Preparing : 1/1

Installing : jdk-17-2000:17.0.1-ga.x86_64 1/1

Running scriptlet: jdk-17-2000:17.0.1-ga.x86_64 1/1

Verifying : jdk-17-2000:17.0.1-ga.x86_64 1/1

Installed:

jdk-17-2000:17.0.1-ga.x86_64

Complete!

Removing intermediate container ced0bdf80a92

---> 2dd8b2ed47d5

Step 5/10 : ADD apache-tomcat-10.1.0-M8.tar.gz /usr/local/

---> 0f2f642717e1

Step 6/10 : RUN mv /usr/local/apache-tomcat-10.1.0-M8 /usr/local/tomcat10

---> Running in 152332dce9dd

Removing intermediate container 152332dce9dd

---> faa12297119d

Step 7/10 : ENV CATALINA_HOME /usr/local/tomcat10

---> Running in f36e315d96ad

Removing intermediate container f36e315d96ad

---> 2ff90ec73018

Step 8/10 : WORKDIR /usr/local/

---> Running in f68564f706e9

Removing intermediate container f68564f706e9

---> 967cb0e0c116

Step 9/10 : EXPOSE 8080

---> Running in fe4e2195ae7a

Removing intermediate container fe4e2195ae7a

---> 30a8e02222a3

Step 10/10 : CMD /usr/local/tomcat10/bin/startup.sh && tail -f 10 /usr/local/tomcat10/logs/catalina.out

---> Running in 773f2e0e8cf2

Removing intermediate container 773f2e0e8cf2

---> d1e09b581106

Successfully built d1e09b581106

Successfully tagged tomcat10:v1.0

build过程中遇到的问题

#问题1:最后没有加 “.”,即没有指明Dockerfile的路径,如果不是标准命名,请使用-f加上文件路径

[root@localhost dockerfile]# docker build --tag tomcat10:v1.0

"docker build" requires exactly 1 argument.

See 'docker build --help'.

Usage: docker build [OPTIONS] PATH | URL | -

Build an image from a Dockerfile

问题2:copy和add只能识别Dockfile所在目录的路径或者所在文件目录内的路径

[root@localhost dockerfile]# docker build -t tomcat10:v1.0 .

Sending build context to Docker daemon 2.048kB

Step 1/10 : FROM centos

---> 5d0da3dc9764

Step 2/10 : MAINTAINER kingbywork

---> Running in acf9a00b67f2

Removing intermediate container acf9a00b67f2

---> 8afd52cfdbf6

Step 3/10 : COPY /home/jdk-17_linux-x64_bin.rpm /usr/loca/

COPY failed: file not found in build context or excluded by .dockerignore: stat home/jdk-17_linux-x64_bin.rpm: file does not exist

问题3:rpm文件容器中不能使用rpm命令安装,而是使用yum -y 绝对路径 进行安装

[root@localhost dockerfile]# vim Dockerfile

[root@localhost dockerfile]# docker build -t tomcat10:v1.0 .

Sending build context to Docker daemon 2.048kB

Step 1/10 : FROM centos

---> 5d0da3dc9764

Step 2/10 : MAINTAINER kingbywork

---> Using cache

---> 8afd52cfdbf6

Step 3/10 : COPY jdk-17_linux-x64_bin.rpm /usr/local/

---> 9f028d1fd7fa

Step 4/10 : RUN RPM -UIV /usr/local/jdk-17_linux-x64_bin.rpm

---> Running in 31f80673df9c

/bin/sh: RPM: command not found

The command '/bin/sh -c RPM -UIV /usr/local/jdk-17_linux-x64_bin.rpm' returned a non-zero code: 127

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值