1、准备镜像文件 tomcat压缩包,jdk的压缩包!
2、编写dockerfile文件,官方命名Dockerfile
,build会自动寻找这个文件,就不需要 -f 指定了!
FROM centos
MAINTAINER ysl<493487822@qq.com>
COPY readme.txt /usr/local/readme.txt
ADD jdk-8u251-linux-x64.tar.gz /usr/local/
ADD apache-tomcat-9.0.35-src.tar.gz /usr/local/
RUN yum -y install vim
ENV MYPATH /usr/local
WORKDIR $MYPATH
ENV JAVA_HOME /usr/local/jdk1.8.0_251
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV CATALINA_HOME /usr/local/apache-tomcat-9.0.35
ENV CATALINA_BASH /usr/local/apache-tomcat-9.0.35
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/bin:$CATALINA_HOME/bin
EXPOSE 8080
CMD /usr/local/apache-tomcat-9.0.35/bin/startup.sh && tail -F /usr/local/apache-tomcat-9.0.35/bin/logs/catalina.out
3、构建镜像
[root@iz2zeaet7s13lfkc8r3e2kz ysl]# docker build -t diytomcat .
Sending build context to Docker daemon 201MB
Step 1/15 : FROM centos
---> 470671670cac
Step 2/15 : MAINTAINER ysl<493487822@qq.com>
---> Using cache
---> fd5e9920907d
Step 3/15 : COPY readme.txt /usr/local/readme.txt
---> c27c87c9a7b8
Step 4/15 : ADD jdk-8u251-linux-x64.tar.gz /usr/local/
---> 195d5de3367b
Step 5/15 : ADD apache-tomcat-9.0.35-src.tar.gz /usr/local/
---> a5d8a5369b1b
Step 6/15 : RUN yum -y install vim
---> Running in dabc304efd48
CentOS-8 - AppStream 857 kB/s | 7.0 MB 00:08
CentOS-8 - Base 701 kB/s | 2.2 MB 00:03
CentOS-8 - Extras 2.6 kB/s | 5.9 kB 00:02
Dependencies resolved.
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
vim-enhanced x86_64 2:8.0.1763-13.el8 AppStream 1.4 M
Installing dependencies:
gpm-libs x86_64 1.20.7-15.el8 AppStream 39 k
vim-common x86_64 2:8.0.1763-13.el8 AppStream 6.3 M
vim-filesystem noarch 2:8.0.1763-13.el8 AppStream 48 k
which x86_64 2.21-10.el8 BaseOS 49 k
Transaction Summary
================================================================================
Install 5 Packages
Total download size: 7.8 M
Installed size: 31 M
Downloading Packages:
(1/5): gpm-libs-1.20.7-15.el8.x86_64.rpm 281 kB/s | 39 kB 00:00
(2/5): vim-filesystem-8.0.1763-13.el8.noarch.rp 454 kB/s | 48 kB 00:00
(3/5): which-2.21-10.el8.x86_64.rpm 374 kB/s | 49 kB 00:00
(4/5): vim-enhanced-8.0.1763-13.el8.x86_64.rpm 829 kB/s | 1.4 MB 00:01
(5/5): vim-common-8.0.1763-13.el8.x86_64.rpm 834 kB/s | 6.3 MB 00:07
--------------------------------------------------------------------------------
Total 904 kB/s | 7.8 MB 00:08
warning: /var/cache/dnf/AppStream-02e86d1c976ab532/packages/gpm-libs-1.20.7-15.el8.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 8483c65d: NOKEY
CentOS-8 - AppStream 1.6 MB/s | 1.6 kB 00:00
Importing GPG key 0x8483C65D:
Userid : "CentOS (CentOS Official Signing Key) <security@centos.org>"
Fingerprint: 99DB 70FA E1D7 CE22 7FB6 4882 05B5 55B3 8483 C65D
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : which-2.21-10.el8.x86_64 1/5
Installing : vim-filesystem-2:8.0.1763-13.el8.noarch 2/5
Installing : vim-common-2:8.0.1763-13.el8.x86_64 3/5
Installing : gpm-libs-1.20.7-15.el8.x86_64 4/5
Running scriptlet: gpm-libs-1.20.7-15.el8.x86_64 4/5
Installing : vim-enhanced-2:8.0.1763-13.el8.x86_64 5/5
Running scriptlet: vim-enhanced-2:8.0.1763-13.el8.x86_64 5/5
Running scriptlet: vim-common-2:8.0.1763-13.el8.x86_64 5/5
Verifying : gpm-libs-1.20.7-15.el8.x86_64 1/5
Verifying : vim-common-2:8.0.1763-13.el8.x86_64 2/5
Verifying : vim-enhanced-2:8.0.1763-13.el8.x86_64 3/5
Verifying : vim-filesystem-2:8.0.1763-13.el8.noarch 4/5
Verifying : which-2.21-10.el8.x86_64 5/5
Installed:
vim-enhanced-2:8.0.1763-13.el8.x86_64 gpm-libs-1.20.7-15.el8.x86_64
vim-common-2:8.0.1763-13.el8.x86_64 vim-filesystem-2:8.0.1763-13.el8.noarch
which-2.21-10.el8.x86_64
Complete!
Removing intermediate container dabc304efd48
---> a23f2b7b0dfd
Step 7/15 : ENV MYPATH /usr/local
---> Running in c6815f1ae0c6
Removing intermediate container c6815f1ae0c6
---> 4898e33f137d
Step 8/15 : WORKDIR $MYPATH
---> Running in f41807a4dcd7
Removing intermediate container f41807a4dcd7
---> 0e0faec6f3b0
Step 9/15 : ENV JAVA_HOME /usr/local/jdk1.8.0_251
---> Running in 99ef8c19aec6
Removing intermediate container 99ef8c19aec6
---> fafd91a43951
Step 10/15 : ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
---> Running in fd23d9d09d63
Removing intermediate container fd23d9d09d63
---> 7075d497243c
Step 11/15 : ENV CATALINA_HOME /usr/local/apache-tomcat-9.0.35
---> Running in 503f5c54948f
Removing intermediate container 503f5c54948f
---> ba6ad879d8c1
Step 12/15 : ENV CATALINA_BASH /usr/local/apache-tomcat-9.0.35
---> Running in 106fb94d57a1
Removing intermediate container 106fb94d57a1
---> 250479e1722e
Step 13/15 : ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/bin:$CATALINA_HOME/bin
---> Running in 3b201dfb577d
Removing intermediate container 3b201dfb577d
---> 7a78f8c1cd8f
Step 14/15 : EXPOSE 8080
---> Running in eab87c07a71d
Removing intermediate container eab87c07a71d
---> ce615e112316
Step 15/15 : CMD /usr/local/apache-tomcat-9.0.35/bin/startup.sh && tail -F /url/local/apache-tomcat-9.0.35/bin/logs/catalina.out
---> Running in 65517b76ae78
Removing intermediate container 65517b76ae78
---> 60e8cd8eda16
Successfully built 60e8cd8eda16
Successfully tagged diytomcat:latest
[root@iz2zeaet7s13lfkc8r3e2kz ysl]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
diytomcat latest 60e8cd8eda16 13 minutes ago 733MB
entrypoint-test latest cd452c66c026 4 hours ago 237MB
cmdtest latest 380b0c95615c 4 hours ago 237MB
mycentos 0.1 a68a7a44878e 5 hours ago 321MB
ysl/centos 1.0 bf97aef123f3 28 hours ago 237MB
mysql 5.7 a4fdfd462add 5 days ago 448MB
nginx latest 9beeba249f3e 10 days ago 127MB
centos latest 470671670cac 4 months ago 237MB
启动并进入
[root@iz2zeaet7s13lfkc8r3e2kz ysl]# docker run -dit -p 9000:8080 --name ysltomcat -v /home/ysl/test:/usr/local/apache-tomcat-9.0.35/webapps/test -v /home/ysl/tomcatlogs/:/usr/local/apache-tomcat-9.0.35/logs diytomcat /bin/bash
[root@d5a15c7850ad local]# ls
apache-tomcat-9.0.35-src etc include lib libexec sbin src
bin games jdk1.8.0_251 lib64 readme.txt share
挂载的目录
访问
[root@iz2zeaet7s13lfkc8r3e2kz ysl]# cd test
[root@iz2zeaet7s13lfkc8r3e2kz test]# mkdir WEB-INF
[root@iz2zeaet7s13lfkc8r3e2kz test]# ls
WEB-INF
[root@iz2zeaet7s13lfkc8r3e2kz test]# cd WEB-INF/
[root@iz2zeaet7s13lfkc8r3e2kz WEB-INF]# vim web.xml
[root@iz2zeaet7s13lfkc8r3e2kz WEB-INF]# cd ..
[root@iz2zeaet7s13lfkc8r3e2kz test]# vim index.jsp
[root@iz2zeaet7s13lfkc8r3e2kz test]# cat index.jsp
lge language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>yslTest</title>
</head>
<body>
Hello World!<br/>
</body>
</html>
发布镜像
发布到DockerHub
登录DockerHub
[root@iz2zeaet7s13lfkc8r3e2kz ysl]# docker login --help
Usage: docker login [OPTIONS] [SERVER]
Log in to a Docker registry.
If no server is specified, the default is defined by the daemon.
Options:
-p, --password string Password
--password-stdin Take the password from stdin
-u, --username string Username
# 登录
[root@iz2zeaet7s13lfkc8r3e2kz ysl]# docker login -u ysltop
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
# 发布
[root@iz2zeaet7s13lfkc8r3e2kz ysl]# docker push ysltop/diytomcat
The push refers to repository [docker.io/ysltop/diytomcat]
An image does not exist locally with the tag: ysltop/diytomcat
# 解决,加一个tag
[root@iz2zeaet7s13lfkc8r3e2kz ysl]# docker tag cd452c66c026 ysltop/tomcat:1.0
再发布
发布到阿里云
登录阿里云
创建命名空间
创建镜像仓库
查看仓库信息
根据阿里云提供的操作
登录
发布