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 mydocker cd mydocker copy /xxx/ ./
3. Create a new Dockerfile file
vi Dockerfile
The file contents are as follows:
FROM java:8 MAINTAINER WORKDIR /test COPY /test/ CMD ["java","-jar","","-=utf-8"]
Code explanation
- FROM java:8 ——Represents that it is built based on java:8 image
- MAINTAINER author—represents that the author is built as author
- WORKDIR /test — means that the working directory in the specified container is /test
- COPY — Copy to container working directory/test
- CMD - Execute the java start jar instruction.
4. Build a mirror
docker build -t app-docker .
It means to build an image from the current directory. This command will package all files in the current directory and send them to the docker engine server, and then build operations based on the Dockerfile on the server.
5. After successful construction, 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, the test directory will inevitably be generated in the container root directory, and there are files in the test directory. The instructions defined by the container are also based on the test directory.
You 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 my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!