gpt4 book ai didi

java - Docker 使用添加的 Java 应用程序创建新镜像

转载 作者:行者123 更新时间:2023-12-01 12:42:49 24 4
gpt4 key购买 nike

假设我想在 dockerfile/java(来自 DockerHub)之上分发一个 Docker 镜像,其中包含位于我的本地盒子中的可执行 Jar 文件。我该怎么做呢?

bash-3.2$ pwd /Users/czou/workspace/echodocker

bash-3.2$ cat Dockerfile

FROM dockerfile/java:latest

MAINTAINER X Y

ADD ../testing/echoservice-0.1.0-SNAPSHOT/ /data/echoservice

EXPOSE 8080

EXPOSE 8081

bash-3.2$ ls ../testing/echoservice-0.1.0-SNAPSHOT/

bin config lib

我们运行“docker build”,它总是给我:

../testing/echoservice-0.1.0-SNAPSHOT/:没有这样的文件或目录

文档要求构建上下文,它的真正含义是什么?我发现它很困惑......

最佳答案

Structure of java aplication

Demo
└── src
| ├── main
| │ ├── java
| │ │ └── org
| │ │ └── demo
| │ │ └── .java
| │ └── resources
| │ └── application.properties
| └── test
| └── java
| └── org
| └── demo
| └── App.java
├──── Dockerfile
├──── pom.xml

Content of Dockerfile

FROM java:8
EXPOSE 8080
ADD /target/demo.jar demo.jar
ENTRYPOINT ["java","-jar","demo.jar"]

Commands to build and run image

  • Go to the directory of project.Lets say D:/Demo
$ cd D/demo
$ mvn clean install
$ docker build demo .
$ docker run -p 8080:8080 -t demo

Check that container is running or not

$ docker ps

The output will be

CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS                    NAMES
55c11a464f5a demo1 "java -jar demo.jar" 21 seconds ago Up About a minute 0.0.0.0:8080->8080/tcp cranky_mayer

Find video at Spring Boot with Docker

关于java - Docker 使用添加的 Java 应用程序创建新镜像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24940165/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com