1.Centos7 environment preparation
At present, Centos supported by docker is version 7 and above, the installation process will not go into details, there are many online
2. Deployment
Go to the new docker folder under /usr/local and import the jar package that has been printed in IDEA or Eclispe
At the same time create a file named Dockerfile and write the following content
FROM java:8
MAINTAINER testuser
VOLUME /tmp
ADD test_old.jar test.jar
RUN bash -c 'touch /test.jar'
EXPOSE 8080
ENTRYPOINT ["java","-jar","/test.jar"]
Then execute to download the mirror image of java:8
docker pull java:8
Then build a mirror
docker build -t test(你的镜像名) .
Then start the mirror
docker run -d --name test -p 8080:8080 test
- -d stands for background operation
Finally, you can notify docker ps to see if the image has been started
Then open the browser in the virtual machine and enter localhost:8080 to access the service (I used the registry service I made myself-Eureka)
Then we actually want to access the service of the virtual machine on the host (my host and the virtual machine are connected by NAT). In the virtual machine, we use ifconfig to check its ip address (such as my 192.168.150.135 here)
Then we went to ping 192.168.150.135 on the host and found that the ping failed. At this time, we found that its ip and virtual machine ip were not in the same network segment in the ipconfig of the host cmd, then we need to set it up at this time
Open the adapter settings, find VMnet8, modify its ipv4 address to the same network segment as shown in the figure, confirm it, ping 192.168.150.135 from the host again and find that the ping is successful, at this time we enter: 192.168.150.135 in the browser address bar: 8080 can be accessed
3. Pull download is slow
Enter Alibaba Cloud Homepage-"Product Classification-"Cloud Computing Fundamentals-"Container Mirroring Service -" Management Console, then log in-"Mirror Accelerator, then select the Linux system version (I am Centos here), find the counter address and copy
Then return to the linux terminal, enter the /etc/docker directory, modify daemon.json (if not, create it yourself) and write the content as shown below
{
"registry-mirrors":["复制的加速镜像地址"]
}
Then restart docker, and then docker pull java:8 again, the download will be fast
sudo systemctl daemon-reload
sudo systemctl restart docker