【Dockerfile镜像制作】

Dockerfile镜像制作

制作Dockerfile文件

做一个springboot应用的镜像,支持启动不同的jar

··下载java镜像

docker pull java:8

··基于java镜像自定义配置文件

#创建配置文件
touch Dockerfile
#编辑文件
vi Dockerfile

Dockerfile内容如下

FROM java:8
ADD /springboot-docker-0.0.1-SNAPSHOT.jar //
ENTRYPOINT [“java”,"-jar","/springboot-docker-0.0.1-SNAPSHOT.jar"]

构建镜像

当前路径下上传springboot-docker-0.0.1-SNAPSHOT.jar文件,根据自己需要构建

[root@localhost docker]# ls
Dockerfile  springboot-docker-0.0.1-SNAPSHOT.jar

开始构建

[root@localhost docker]# docker build -t springboot-docker .
#注意最后的点,这是用于复制文件到镜像的,运行结果如下
[root@localhost docker]# docker build -t springboot-docker .
Sending build context to Docker daemon  17.56MB
Step 1/3 : FROM java:8
8: Pulling from library/java
5040bd298390: Pull complete 
fce5728aad85: Pull complete 
76610ec20bf5: Pull complete 
60170fec2151: Pull complete 
e98f73de8f0d: Pull complete 
11f7af24ed9c: Pull complete 
49e2d6393f32: Pull complete 
bb9cdec9c7f3: Pull complete 
Digest: sha256:c1ff613e8ba25833d2e1940da0940c3824f03f802c449f3d1815a66b7f8c0e9d
Status: Downloaded newer image for java:8
 ---> d23bdf5b1b1b
Step 2/3 : ADD /springboot-docker-0.0.1-SNAPSHOT.jar //
 ---> 2349781904af
Step 3/3 : ENTRYPOINT ["java","-jar","/springboot-docker-0.0.1-SNAPSHOT.jar"]
 ---> Running in 32bf21786f84
Removing intermediate container 32bf21786f84
 ---> 8734a1fc98cf
Successfully built 8734a1fc98cf
Successfully tagged springboot-docker:latest

查看镜像列表

[root@localhost ~]# docker images
REPOSITORY          TAG       IMAGE ID       CREATED         SIZE
springboot-docker   latest    8734a1fc98cf   22 hours ago    661MB
alpine              latest    a24bb4013296   21 months ago   5.57MB
centos              centos7   b5b4d78bc90c   22 months ago   203MB
java                8         d23bdf5b1b1b   5 years ago     643MB

使用镜像运行容器

[root@localhost ~]# docker run -d --name dspringboot-docker-c -p 10000:8080 springboot-docker
616440946cf0f670d570ecaf20d8664f145e3212f26a902e4b2d9d22159c8a63

查看当前运行的容器

[root@localhost ~]# docker ps -a
CONTAINER ID   IMAGE               COMMAND                  CREATED          STATUS                       PORTS                                         NAMES
20bacd4bafee   springboot-docker   "java -jar /springbo…"   58 seconds ago   Up 57 seconds                0.0.0.0:10000->8080/tcp, :::10000->8080/tcp   dspringboot-docker-c

查看log

[root@localhost ~]# docker logs -f -t --tail 50 616440946cf0f670d570ecaf20d8664f145e3212f26a902e4b2d9d22159c8a63
2022-03-03T15:30:26.672840821Z 
2022-03-03T15:30:26.672870374Z   .   ____          _            __ _ _
2022-03-03T15:30:26.672873752Z  /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
2022-03-03T15:30:26.672875754Z ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
2022-03-03T15:30:26.672877641Z  \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
2022-03-03T15:30:26.672879436Z   '  |____| .__|_| |_|_| |_\__, | / / / /
2022-03-03T15:30:26.672881660Z  =========|_|==============|___/=/_/_/_/
2022-03-03T15:30:26.691832981Z  :: Spring Boot ::                (v2.6.4)
2022-03-03T15:30:26.691853798Z 
2022-03-03T15:30:26.829813792Z 2022-03-03 15:30:26.826  INFO 1 --- [           main] c.n.d.s.SpringbootDockerApplication      : Starting SpringbootDockerApplication v0.0.1-SNAPSHOT using Java 1.8.0_111 on 616440946cf0 with PID 1 (/springboot-docker-0.0.1-SNAPSHOT.jar started by root in /)
2022-03-03T15:30:26.829835300Z 2022-03-03 15:30:26.829  INFO 1 --- [           main] c.n.d.s.SpringbootDockerApplication      : No active profile set, falling back to 1 default profile: "default"
2022-03-03T15:30:28.646110255Z 2022-03-03 15:30:28.645  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2022-03-03T15:30:28.678748952Z 2022-03-03 15:30:28.677  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2022-03-03T15:30:28.678774043Z 2022-03-03 15:30:28.677  INFO 1 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.58]
2022-03-03T15:30:28.786696955Z 2022-03-03 15:30:28.785  INFO 1 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2022-03-03T15:30:28.786717348Z 2022-03-03 15:30:28.786  INFO 1 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1861 ms
2022-03-03T15:30:30.002076758Z 2022-03-03 15:30:30.000  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2022-03-03T15:30:30.017918245Z 2022-03-03 15:30:30.017  INFO 1 --- [           main] c.n.d.s.SpringbootDockerApplication      : Started SpringbootDockerApplication in 4.005 seconds (JVM running for 5.335)
r

访问springboot

查看端口
[root@localhost ~]# netstat -lnp|grep 10000
tcp        0      0 0.0.0.0:10000           0.0.0.0:*               LISTEN      54995/docker-proxy  
tcp6       0      0 :::10000                :::*                    LISTEN      54999/docker-proxy  


http://192.168.247.134:10000/

Hello world

如果觉得还不错,麻烦点个赞,谢谢大家,祝你们顺风顺水!!!

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值