docker opens remote access interface
docker has to set up the environment, so it won't be repeated here. It won't have to go to Baidu by itself, just a few commands.
To push a local image to the docker container of alicloud, you need to enable remote access
First edit the host file of docker / lib/systemd/system/docker.service
vi /lib/systemd/system/docker.service
Modify the line starting with ExecStart. Here is Tencent cloud server center os 7. After modification, it is:
Save the file after modification, and then notify and restart the service
systemctl daemon-reload service docker restart
However, if you restart the docker by executing service docker restart, an error will be reported. View: https://blog.csdn.net/hdu09075340/article/details/101060655
After the restart is completed, you can verify it on the local machine and view the version information through the curl command
curl http://localhost:2375/version
Open the white list to enable the client to access remotely
We have opened the port on the remote machine, but generally the ECS needs to set the port white list to access. The specific setting of the port white list is not introduced here. After the setting is completed, it can be accessed through the Internet ip in the windows machine browser
Local docker project publishing image to remote server
Technology that doesn't aim at actual combat is to play hooligans. Suppose there is a demand now: as a coder, I have developed a blog system, and now I want to deploy it to a remote server after the development.
Traditional deployment plan
Install jdk and tomcat on the server - > package Projects - > upload FTP - > start projects
docker deployment scheme
Docker deployment scheme: project integration docker plug-in - > local packaging - > project building image to remote machine - > remote server downloading image and starting
Through the comparison of the two release processes, we can know the merits and demerits of each. There is no more burden here, and we will start the second plan!
Configure the local environment variables first
As shown in the figure, configure the remote tcp connection of receiver ﹣ host.
Import the project into idea. Let's see the main configuration related to docker
Dockerfile file FROM openjdk:8-jdk-alpine VOLUME /tmp ADD demo-1.0.0-SNAPSHOT.jar app.jar ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
maven dependence
<plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>1.0.0</version> <configuration> <imageName>${docker.image.prefix}/${project.artifactId}</imageName> <dockerDirectory>src/main/docker</dockerDirectory> <dockerHost>http://10.254.193.119:2375</dockerHost> <resources> <resource> <targetPath>/</targetPath> <directory>${project.build.directory}</directory> <include>${project.build.finalName}.jar</include> </resource> </resources> </configuration> </plugin>
Using the docker plug-in of idea to build the image
Package the project first
After packing, click docker:build
After the successful construction, the log is as follows:
D:\devsoft\Java\jdk1.8.0_121\bin\java.exe -Dmaven.multiModuleProjectDirectory=D:\Learning-materials\microservices\springcloud-greenwich-github\MicroservicesGreenwich\demo -Dmaven.home=D:\devsoft\apache-maven-3.5.0 -Dclassworlds.conf=D:\devsoft\apache-maven-3.5.0\bin\m2.conf "-Dmaven.ext.class.path=D:\Program Files\JetBrains\IntelliJ IDEA 2019.2\plugins\maven\lib\maven-event-listener.jar" "-javaagent:D:\Program Files\JetBrains\IntelliJ IDEA 2019.2\lib\idea_rt.jar=53271:D:\Program Files\JetBrains\IntelliJ IDEA 2019.2\bin" -Dfile.encoding=UTF-8 -classpath D:\devsoft\apache-maven-3.5.0\boot\plexus-classworlds-2.5.2.jar org.codehaus.classworlds.Launcher -Didea.version2019.2 -s D:\devsoft\apache-maven-3.5.0\conf\settings.xml com.spotify:docker-maven-plugin:1.0.0:build [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building demo 1.0.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- docker-maven-plugin:1.0.0:build (default-cli) @ demo --- [INFO] Using authentication suppliers: [ConfigFileRegistryAuthSupplier] [INFO] Copying D:\Learning-materials\microservices\springcloud-greenwich-github\MicroservicesGreenwich\demo\target\demo-1.0.0-SNAPSHOT.jar -> D:\Learning-materials\microservices\springcloud-greenwich-github\MicroservicesGreenwich\demo\target\docker\demo-1.0.0-SNAPSHOT.jar [INFO] Copying src\main\docker\Dockerfile -> D:\Learning-materials\microservices\springcloud-greenwich-github\MicroservicesGreenwich\demo\target\docker\Dockerfile [INFO] Building image demo-docker/demo Step 1/4 : FROM openjdk:8-jdk-alpine Pulling from library/openjdk e7c96db7181b: Already exists f910a506b6cb: Pulling fs layer c2274a1a0e27: Pulling fs layer f910a506b6cb: Downloading [==================================================>] 238B/238B f910a506b6cb: Verifying Checksum f910a506b6cb: Download complete f910a506b6cb: Extracting [==================================================>] 238B/238B f910a506b6cb: Extracting [==================================================>] 238B/238B f910a506b6cb: Pull complete c2274a1a0e27: Downloading [> ] 524.5kB/70.73MB c2274a1a0e27: Downloading [=> ] 2.1MB/70.73MB c2274a1a0e27: Downloading [==> ] 3.675MB/70.73MB c2274a1a0e27: Downloading [===> ] 4.725MB/70.73MB c2274a1a0e27: Downloading [====> ] 6.825MB/70.73MB c2274a1a0e27: Downloading [=====> ] 8.4MB/70.73MB c2274a1a0e27: Downloading [=======> ] 9.975MB/70.73MB c2274a1a0e27: Downloading [========> ] 11.55MB/70.73MB c2274a1a0e27: Downloading [=========> ] 13.12MB/70.73MB c2274a1a0e27: Downloading [==========> ] 14.7MB/70.73MB c2274a1a0e27: Downloading [===========> ] 16.27MB/70.73MB c2274a1a0e27: Downloading [============> ] 17.85MB/70.73MB c2274a1a0e27: Downloading [=============> ] 19.42MB/70.73MB c2274a1a0e27: Downloading [==============> ] 20.47MB/70.73MB c2274a1a0e27: Downloading [===============> ] 22.05MB/70.73MB c2274a1a0e27: Downloading [================> ] 23.62MB/70.73MB c2274a1a0e27: Downloading [=================> ] 25.2MB/70.73MB c2274a1a0e27: Downloading [==================> ] 26.77MB/70.73MB c2274a1a0e27: Downloading [====================> ] 28.35MB/70.73MB c2274a1a0e27: Downloading [=====================> ] 29.92MB/70.73MB c2274a1a0e27: Downloading [=====================> ] 30.97MB/70.73MB c2274a1a0e27: Downloading [=======================> ] 32.55MB/70.73MB c2274a1a0e27: Downloading [=======================> ] 33.6MB/70.73MB c2274a1a0e27: Downloading [========================> ] 34.12MB/70.73MB c2274a1a0e27: Downloading [========================> ] 35.17MB/70.73MB c2274a1a0e27: Downloading [=========================> ] 35.7MB/70.73MB c2274a1a0e27: Downloading [=========================> ] 36.22MB/70.73MB c2274a1a0e27: Downloading [=========================> ] 36.75MB/70.73MB c2274a1a0e27: Downloading [==========================> ] 37.27MB/70.73MB c2274a1a0e27: Downloading [==========================> ] 37.8MB/70.73MB c2274a1a0e27: Downloading [===========================> ] 38.32MB/70.73MB c2274a1a0e27: Downloading [===========================> ] 38.85MB/70.73MB c2274a1a0e27: Downloading [===========================> ] 39.37MB/70.73MB c2274a1a0e27: Downloading [============================> ] 39.9MB/70.73MB c2274a1a0e27: Downloading [============================> ] 40.42MB/70.73MB c2274a1a0e27: Downloading [============================> ] 40.95MB/70.73MB c2274a1a0e27: Downloading [=============================> ] 41.47MB/70.73MB c2274a1a0e27: Downloading [=============================> ] 42MB/70.73MB c2274a1a0e27: Downloading [==============================> ] 42.52MB/70.73MB c2274a1a0e27: Downloading [==============================> ] 43.05MB/70.73MB c2274a1a0e27: Downloading [==============================> ] 43.57MB/70.73MB c2274a1a0e27: Downloading [===============================> ] 44.1MB/70.73MB c2274a1a0e27: Downloading [===============================> ] 44.62MB/70.73MB c2274a1a0e27: Downloading [===============================> ] 45.15MB/70.73MB c2274a1a0e27: Downloading [================================> ] 45.67MB/70.73MB c2274a1a0e27: Downloading [================================> ] 46.2MB/70.73MB c2274a1a0e27: Downloading [=================================> ] 46.72MB/70.73MB c2274a1a0e27: Downloading [=================================> ] 47.25MB/70.73MB c2274a1a0e27: Downloading [=================================> ] 47.77MB/70.73MB c2274a1a0e27: Downloading [==================================> ] 48.3MB/70.73MB c2274a1a0e27: Downloading [==================================> ] 48.82MB/70.73MB c2274a1a0e27: Downloading [==================================> ] 49.35MB/70.73MB c2274a1a0e27: Downloading [===================================> ] 49.87MB/70.73MB c2274a1a0e27: Downloading [===================================> ] 50.4MB/70.73MB c2274a1a0e27: Downloading [===================================> ] 50.92MB/70.73MB c2274a1a0e27: Downloading [====================================> ] 51.45MB/70.73MB c2274a1a0e27: Downloading [====================================> ] 51.97MB/70.73MB c2274a1a0e27: Downloading [=====================================> ] 52.5MB/70.73MB c2274a1a0e27: Downloading [=====================================> ] 53.02MB/70.73MB c2274a1a0e27: Downloading [=====================================> ] 53.55MB/70.73MB c2274a1a0e27: Downloading [======================================> ] 54.07MB/70.73MB c2274a1a0e27: Downloading [======================================> ] 54.6MB/70.73MB c2274a1a0e27: Downloading [======================================> ] 55.12MB/70.73MB c2274a1a0e27: Downloading [=======================================> ] 55.65MB/70.73MB c2274a1a0e27: Downloading [=======================================> ] 56.17MB/70.73MB c2274a1a0e27: Downloading [========================================> ] 56.7MB/70.73MB c2274a1a0e27: Downloading [========================================> ] 57.22MB/70.73MB c2274a1a0e27: Downloading [========================================> ] 57.75MB/70.73MB c2274a1a0e27: Downloading [=========================================> ] 58.27MB/70.73MB c2274a1a0e27: Downloading [=========================================> ] 58.8MB/70.73MB c2274a1a0e27: Downloading [=========================================> ] 59.32MB/70.73MB c2274a1a0e27: Downloading [==========================================> ] 59.85MB/70.73MB c2274a1a0e27: Downloading [==========================================> ] 60.37MB/70.73MB c2274a1a0e27: Downloading [===========================================> ] 60.9MB/70.73MB c2274a1a0e27: Downloading [===========================================> ] 61.42MB/70.73MB c2274a1a0e27: Downloading [===========================================> ] 61.95MB/70.73MB c2274a1a0e27: Downloading [============================================> ] 62.47MB/70.73MB c2274a1a0e27: Downloading [============================================> ] 63MB/70.73MB c2274a1a0e27: Downloading [============================================> ] 63.52MB/70.73MB c2274a1a0e27: Downloading [=============================================> ] 64.05MB/70.73MB c2274a1a0e27: Downloading [=============================================> ] 64.57MB/70.73MB c2274a1a0e27: Downloading [==============================================> ] 65.1MB/70.73MB c2274a1a0e27: Downloading [==============================================> ] 65.62MB/70.73MB c2274a1a0e27: Downloading [==============================================> ] 66.15MB/70.73MB c2274a1a0e27: Downloading [===============================================> ] 66.67MB/70.73MB c2274a1a0e27: Downloading [===============================================> ] 67.2MB/70.73MB c2274a1a0e27: Downloading [===============================================> ] 67.72MB/70.73MB c2274a1a0e27: Downloading [================================================> ] 68.25MB/70.73MB c2274a1a0e27: Downloading [================================================> ] 68.77MB/70.73MB c2274a1a0e27: Downloading [================================================> ] 69.3MB/70.73MB c2274a1a0e27: Downloading [=================================================> ] 69.82MB/70.73MB c2274a1a0e27: Downloading [=================================================> ] 70.35MB/70.73MB c2274a1a0e27: Verifying Checksum c2274a1a0e27: Download complete c2274a1a0e27: Extracting [> ] 557.1kB/70.73MB c2274a1a0e27: Extracting [=> ] 1.671MB/70.73MB c2274a1a0e27: Extracting [=> ] 2.785MB/70.73MB c2274a1a0e27: Extracting [===> ] 4.456MB/70.73MB c2274a1a0e27: Extracting [====> ] 6.128MB/70.73MB c2274a1a0e27: Extracting [======> ] 8.913MB/70.73MB c2274a1a0e27: Extracting [=======> ] 11.14MB/70.73MB c2274a1a0e27: Extracting [=========> ] 13.93MB/70.73MB c2274a1a0e27: Extracting [===========> ] 16.15MB/70.73MB c2274a1a0e27: Extracting [=============> ] 18.94MB/70.73MB c2274a1a0e27: Extracting [===============> ] 21.73MB/70.73MB c2274a1a0e27: Extracting [================> ] 23.95MB/70.73MB c2274a1a0e27: Extracting [==================> ] 26.18MB/70.73MB c2274a1a0e27: Extracting [====================> ] 28.41MB/70.73MB c2274a1a0e27: Extracting [=====================> ] 30.64MB/70.73MB c2274a1a0e27: Extracting [=======================> ] 32.87MB/70.73MB c2274a1a0e27: Extracting [========================> ] 35.09MB/70.73MB c2274a1a0e27: Extracting [==========================> ] 37.32MB/70.73MB c2274a1a0e27: Extracting [===========================> ] 39.55MB/70.73MB c2274a1a0e27: Extracting [=============================> ] 42.34MB/70.73MB c2274a1a0e27: Extracting [===============================> ] 45.12MB/70.73MB c2274a1a0e27: Extracting [=================================> ] 47.91MB/70.73MB c2274a1a0e27: Extracting [===================================> ] 49.58MB/70.73MB c2274a1a0e27: Extracting [====================================> ] 51.81MB/70.73MB c2274a1a0e27: Extracting [======================================> ] 54.03MB/70.73MB c2274a1a0e27: Extracting [=======================================> ] 56.26MB/70.73MB c2274a1a0e27: Extracting [=========================================> ] 58.49MB/70.73MB c2274a1a0e27: Extracting [==========================================> ] 60.72MB/70.73MB c2274a1a0e27: Extracting [============================================> ] 62.95MB/70.73MB c2274a1a0e27: Extracting [=============================================> ] 64.62MB/70.73MB c2274a1a0e27: Extracting [==============================================> ] 65.73MB/70.73MB c2274a1a0e27: Extracting [===============================================> ] 66.85MB/70.73MB c2274a1a0e27: Extracting [================================================> ] 68.52MB/70.73MB c2274a1a0e27: Extracting [=================================================> ] 70.19MB/70.73MB c2274a1a0e27: Extracting [==================================================>] 70.73MB/70.73MB c2274a1a0e27: Pull complete Digest: sha256:94792824df2df33402f201713f932b58cb9de94a0cd524164a0f2283343547b3 Status: Downloaded newer image for openjdk:8-jdk-alpine ---> a3562aa0b991 Step 2/4 : VOLUME /tmp ---> Running in 9866501a71d4 Removing intermediate container 9866501a71d4 ---> f4247134db56 Step 3/4 : ADD demo-1.0.0-SNAPSHOT.jar app.jar ---> 9fe41d8b6c79 Step 4/4 : ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"] ---> Running in 619d8b8027ef Removing intermediate container 619d8b8027ef ---> 5567045a3623 ProgressMessage{id=null, status=null, stream=null, error=null, progress=null, progressDetail=null} Successfully built 5567045a3623 Successfully tagged demo-docker/demo:latest [INFO] Built demo-docker/demo [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 58.843 s [INFO] Finished at: 2020-01-16T15:58:07+08:00 [INFO] Final Memory: 27M/459M [INFO] ------------------------------------------------------------------------
At this time, we log in to the remote machine to see if the image is published.
You can see that the image has been built and uploaded to the image warehouse, and the image id is the same. Then it's done! All images are available. Just build the container with one command and start it! Exciting time is coming!
docker run -p 8181:8080 --name demo -d 5567045a3623
Normal startup, view project allow log
docker logs -f demo
Reference link:
https://blog.csdn.net/lzp492782442/article/details/103082541