How to turn a jar package into a docker container

How to turn a jar package into a docker container

How to turn a jar package into a docker container

1. First download the java image

docker pull java:8

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

mkdir mydocker
cd mydocker
copy /xxx/app.jar ./

3. Create a new Dockerfile

vi Dockerfile

The file contents are as follows:

FROM java:8
MAINTAINER freebytes.net
WORKDIR /test
COPY app.jar /test/app.jar
CMD ["java","-jar","app.jar","-Dfile.encoding=utf-8"]

Code Explanation

  • FROM java:8 —— indicates that the image is built based on java:8
  • MAINTAINER author——Indicates that the author of the build 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 java command to start the jar.

4. Build an image

docker build -t app-docker .

Indicates building an image from the current directory. This command will package all the files in the current directory and send them to the Docker engine server, and then build the image according to the Dockerfile on the server.

5. After the build is successful, start the container

docker run -it -p 9013:8088 –name app -d my-docker

According to the Dockerfile configuration just now, after the container is generated, a test directory will inevitably be generated in the container root directory, and the app.jar file will exist in the test directory. The container executes the instructions defined by CMD based on the test directory.

Can enter the container to view

docker exec -it app /bin/bash

This is the end of this article about how to turn a jar package into a docker container. For more information about how to turn a jar package into a docker container, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Detailed explanation of how to deploy SpringBoot in docker and replace jar packages
  • Docker solves the problem that JDK's jmap and other commands cannot be used in openjdk containers
  • How to install openjdk in docker and run the jar package

<<:  Solve MySQL login error: 'Access denied for user 'root'@'localhost'

>>:  Detailed explanation of the abbreviation of state in react

Recommend

How to use geoip to restrict regions in nginx

This blog is a work note environment: nginx versi...

How to prevent website content from being included in search engines

Usually the goal of building a website is to have...

How to use skeleton screen in vue project

Nowadays, application development is basically se...

idea uses docker plug-in to achieve one-click automated deployment

Table of contents environment: 1. Docker enables ...

Understanding JavaScript prototype chain

Table of contents 1. Understanding the Equality R...

Beginners learn some HTML tags (3)

Beginners who are exposed to HTML learn some HTML...

How React Hooks Work

Table of contents 1. React Hooks vs. Pure Functio...

How to match the size of text in web design: small text, big experience

With the rise of mobile terminals such as iPad, p...

Various transformation effects of HTML web page switching

<META http-equiv="Page-Enter" CONTENT...

How to implement remote access control in Centos 7.4

1. SSH remote management SSH is a secure channel ...

Summary of MySQL database usage specifications

Introduction: Regarding MySQL database specificat...

Detailed example of SpringBoot+nginx to achieve resource upload function

Recently, I have been learning to use nginx to pl...

Conflict resolution when marquee and flash coexist in a page

The main symptom of the conflict is that the FLASH...