Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to turn a jar package into a docker container

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how to turn a jar package into a docker container. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

How to turn a jar package into a docker container

1. Download the java image first.

Docker pull java:8

2. Create a new working directory and copy the jar package into it.

Mkdir mydockercd mydockercopy / xxx/app.jar. /

3. Create a new Dockerfile file

Vi Dockerfile

The contents of the document are as follows:

FROM java:8MAINTAINER freebytes.netWORKDIR / testCOPY app.jar / test/app.jarCMD ["java", "- jar", "app.jar", "- Dfile.encoding=utf-8"]

Code interpretation

FROM java:8-indicates that it is built based on java:8 images

MAINTAINER author-- indicates that the builder is author.

WORKDIR / test-indicates that the working directory in the specified container is / test

COPY-copy app.jar to the container working directory / test

CMD-executes the instructions of java to start jar.

4. Build an image

Docker build-t app-docker.

It means to build an image from the current directory. This command will package and send all the files in the current directory to the server of the docker engine, and then build according to Dockerfile on the server.

5. After the construction is successful, start the container

Docker run-it-p 9013 name app 8088-name app-d my-docker

According to the Dockerfile configuration just now, after the container is generated, the test directory will be generated under the container root directory, and there is an app.jar file in the test directory. The instructions for the container to execute the CMD definition are also based on the test directory.

You can enter the inside of the container for viewing

Docker exec-it app / bin/bash Thank you for your reading! This is the end of this article on "how to turn a jar package into a docker container". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report