Article directory
-
- Docker installation and deployment of pagoda servers for java projects
- View container commands
- deploy java project
- You must first enter this folder to execute the start java command
- enter folder command
- This is used by others to use this to ensure that your docker has jdk1.8
- Docker installs jdk1.8, see the link below for this article
- This is the jdk1.8 installed in my own pagoda. Note that you need to replace jshepr with your own jar name in lowercase.
- The following commands related to jshepr must be changed to their own jar written above
- 3) View the created image and create a container to run. 9999 here is the port of the configuration file in the project, which needs to be mapped to port 7003 of the server to access
Docker installation and deployment of pagoda servers for java projects
1. First make sure that docker is not installed, if installed yum remove docker uninstall docker
2. Install docker
yum install docker
3. Check the docker version
docker -v
4. Check the mirror and test to download an nginx mirror
docker images
docker pull nginx #获取最新版的nginx也可以指定版本
5. Start the nginx image with docker to create a new container and run it
#使用镜像 nginx:latest,以后台模式启动一个容器,将容器的 80 端口映射到主机的 8080 端口
docker run -it -p 8080:80 --name test -d nginx:latest
View container commands
docker ps
6. Delete the mirror image (the container must be stopped before deleting the mirror image)
(1) Stop the container
docker stop 容器ID
(2) Delete the container
docker rm 容器ID
(3) Delete the image
docker rmi 容器ID
deploy java project
You must first enter this folder to execute the start java command
enter folder command
cd /ycw/docker
7. Make your own image, deploy and run it (prepare the jar package in advance,)
(1) Make a DockerFile file
This is used by others to use this to ensure that your docker has jdk1.8
Docker installs jdk1.8, see the link below for this article
http://t.csdn.cn/xMcB9
FROM java:8
MAINTAINER jshepr
COPY jshepr.jar /usr/local/jshepr.jar
ENTRYPOINT [“java”, “-jar”, “/usr/local/jshepr.jar”]
This is the jdk1.8 installed in my own pagoda. Note that you need to replace jshepr with your own jar name in lowercase.
FROM openjdk:8
MAINTAINER jshepr
# 设置JAVA_HOME环境变量
ENV JAVA_HOME=/usr/local/btjdk/jdk8
ENV PATH=$PATH:$JAVA_HOME/bin
# 复制jar文件到容器
COPY jshepr.jar /usr/local/jshepr.jar
# 容器入口点
ENTRYPOINT ["java", "-jar", "/usr/local/jshepr.jar"]
(2) build to build the image (at this time, the current directory is the same as the directory where the DockerFile is located, pay attention to the path)
The following commands related to jshepr must be changed to their own jar written above
docker build -f DockerFile -t jshepr:1.0 .
3) View the created image and create a container to run. 9999 here is the port of the configuration file in the project, which needs to be mapped to port 7003 of the server to access
#了
docker images
docker run -it -p 7003:9999 --name yyy -d jshepr:1.0
docker ps
(4) Check the running results
Enter IP:Port access