Dockerfile镜像基于centos7-tomcat9

38 篇文章 0 订阅

Dockerfile镜像制作

需要的文件

[root@localhost tmp]# ll Dockerfile jdk-8u251-linux-x64.tar.gz apache-tomcat-9.0.35.tar.gz 
-rw-r--r-- 1 root root  11188192 528 16:12 apache-tomcat-9.0.35.tar.gz
-rwxr-xr-x 1 root root       870 77 11:18 Dockerfile
-rw-r--r-- 1 root root 195132576 528 16:39 jdk-8u251-linux-x64.tar.gz

编写Dockerfile

[root@localhost tmp]# cat Dockerfile 
#1.指定基础镜像,并且必须是第一条指令
FROM centos:7

#2.指明该镜像的作者和其电子邮件
MAINTAINER xhx "1135014515@qq.com"

#3.在构建镜像时,指定镜像的工作目录,之后的命令都是基于此工作目录,如果不存在,则会创建目录
WORKDIR /opt

#4.一个复制命令,把jdk安装文件复制到镜像中,语法:ADD <src>... <dest>,注意:jdk*.tar.gz使用的是相对路径
ADD jdk-8u251-linux-x64.tar.gz /xhx/jdk/

ADD apache-tomcat-9.0.35.tar.gz /opt
EXPOSE 8080

#5.配置环境变量
ENV JAVA_HOME=/xhx/jdk/jdk1.8.0_251
ENV CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV PATH=$JAVA_HOME/bin:$PATH

ENTRYPOINT /opt/apache-tomcat-9.0.35/bin/startup.sh && tail -f /opt/apache-tomcat-9.0.35/logs/catalina.out
#容器启动时需要执行的命令
#CMD ["java","-version"]

构建镜像

[root@localhost tmp]# docker build -t cemtos7tomcat9jdk8 .
Sending build context to Docker daemon  670.7MB
Step 1/10 : FROM centos:7
 ---> b5b4d78bc90c
Step 2/10 : MAINTAINER xhx "1135014515@qq.com"
 ---> Using cache
 ---> e9339ad8c365
Step 3/10 : ADD jdk-8u251-linux-x64.tar.gz /xhx/jdk/
 ---> c825cfd6c84a
Step 4/10 : WORKDIR /opt
 ---> Running in 35dad8279b79
Removing intermediate container 35dad8279b79
 ---> fb45a3b8e075
Step 5/10 : ADD apache-tomcat-9.0.35.tar.gz /opt
 ---> e518d183c100
Step 6/10 : EXPOSE 8080
 ---> Running in 0428392d6e2a
Removing intermediate container 0428392d6e2a
 ---> 69483c392d32
Step 7/10 : ENV JAVA_HOME=/xhx/jdk/jdk1.8.0_251
 ---> Running in 86332eec01e9
Removing intermediate container 86332eec01e9
 ---> 0da4d2a38fb0
Step 8/10 : ENV CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
 ---> Running in 748872cd9edb
Removing intermediate container 748872cd9edb
 ---> 35056bbb255e
Step 9/10 : ENV PATH=$JAVA_HOME/bin:$PATH
 ---> Running in 3b1bcada03bb
Removing intermediate container 3b1bcada03bb
 ---> b2ba2e952339
Step 10/10 : ENTRYPOINT /opt/apache-tomcat-9.0.35/bin/startup.sh && tail -f /opt/apache-tomcat-9.0.35/logs/catalina.out
 ---> Running in 7eebb17a6d3c
Removing intermediate container 7eebb17a6d3c
 ---> eb90066f69df
Successfully built eb90066f69df
Successfully tagged cemtos7tomcat9jdk8:latest

查看镜像

[root@localhost tmp]# docker images
REPOSITORY           TAG                 IMAGE ID            CREATED             SIZE
cemtos7tomcat9jdk8   latest              eb90066f69df        48 seconds ago      625MB

运行镜像

[root@localhost tmp]# docker run -itd --name cemtos7tomcat9jdk1.8 cemtos7tomcat9jdk8 -p 80:8080 /bin/bash
3bc3ff364d64811fc7145a9d116f1a1b722faab0ae8c5d6b3baf450e98a376c0

查看容器

[root@localhost tmp]# docker run -itd --name cemtos7tomcat9jdk18 -p 80:8080 cemtos7tomcat9jdk8 /bin/bash 
1530d502372ad1b76c28768d0b88098ca1fe15aca6045ac8889d69223645fbcf
[root@localhost tmp]# docker ps
CONTAINER ID        IMAGE                COMMAND                  CREATED             STATUS              PORTS                    NAMES
1530d502372a        cemtos7tomcat9jdk8   "/bin/sh -c '/opt/ap…"   2 seconds ago       Up 2 seconds        0.0.0.0:80->8080/tcp     cemtos7tomcat9jdk18

查看效果
在这里插入图片描述
登录镜像仓库

[root@localhost tmp]# sudo docker login --username=17606224944 registry.cn-hangzhou.aliyuncs.com
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

将镜像推送到Registry
$ sudo docker login --username=17606224944 registry.cn-hangzhou.aliyuncs.com
$ sudo docker tag [ImageId] registry.cn-hangzhou.aliyuncs.com/xinhuixu/xinhuixu_repositories:[镜像版本号]
$ sudo docker push registry.cn-hangzhou.aliyuncs.com/xinhuixu/xinhuixu_repositories:[镜像版本号]

镜像打标签

[root@localhost tmp]# sudo docker tag eb90066f69df registry.cn-hangzhou.aliyuncs.com/xinhuixu/xinhuixu_repositories:v1
[root@localhost tmp]# docker images
REPOSITORY                                                         TAG                 IMAGE ID            CREATED             SIZE
cemtos7tomcat9jdk8                                                 latest              eb90066f69df        28 minutes ago      625MB
registry.cn-hangzhou.aliyuncs.com/xinhuixu/xinhuixu_repositories   v1                  eb90066f69df        28 minutes ago      625MB

推送到镜像仓库

[root@localhost tmp]# docker push registry.cn-hangzhou.aliyuncs.com/xinhuixu/xinhuixu_repositories:v1
The push refers to repository [registry.cn-hangzhou.aliyuncs.com/xinhuixu/xinhuixu_repositories]
4d737679f9b7: Pushed 
c4f068581146: Pushed 
edf3aa290fb3: Pushed 
v1: digest: sha256:1001df08bab80d90f87c9c8317d560a548a37992a1b257f0614a929754cf2939 size: 954

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

主主主主公

你的鼓励将大动力作的最是我创

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值