仓库联动"/>
idea springboot docker 私有仓库联动
文章目录
- 1 idea直接构建docker 镜像
- 1.1 服务器配置
- 1.2 刷新配置重启docker
- 1.3 boot项目添加插件
- 1.5 使用mvn 命令打包上传docker
- 1.6 私有仓库查询
- 1.7 宿主机检查
- 1.8 创建并启动容器
- 1.9 测试
1 idea直接构建docker 镜像
1.1 服务器配置
修改宿主机,似的宿主机可以被远程访问
vi /lib/systemd/system/docker.service
其中ExecStart=后添加配置‐H tcp://0.0.0.0:2375 ‐H unix:///var/run/docker.sock[root@localhost ~]# vim /lib/systemd/system/docker.service
[root@localhost ~]# cat /lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=
After=network.target
Wants=docker-storage-setup.service
Requires=docker-cleanup.timer[Service]
Type=notify
NotifyAccess=main
EnvironmentFile=-/run/containers/registries.conf
EnvironmentFile=-/etc/sysconfig/docker
EnvironmentFile=-/etc/sysconfig/docker-storage
EnvironmentFile=-/etc/sysconfig/docker-network
Environment=GOTRACEBACK=crash
Environment=DOCKER_HTTP_HOST_COMPAT=1
Environment=PATH=/usr/libexec/docker:/usr/bin:/usr/sbin
ExecStart=/usr/bin/dockerd-current \--add-runtime docker-runc=/usr/libexec/docker/docker-runc-current \--default-runtime=docker-runc \--exec-opt native.cgroupdriver=systemd \--userland-proxy-path=/usr/libexec/docker/docker-proxy-current \--init-path=/usr/libexec/docker/docker-init-current \--seccomp-profile=/etc/docker/seccomp.json \$OPTIONS \$DOCKER_STORAGE_OPTIONS \$DOCKER_NETWORK_OPTIONS \$ADD_REGISTRY \$BLOCK_REGISTRY \$INSECURE_REGISTRY \$REGISTRIES \-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=1048576
LimitNPROC=1048576
LimitCORE=infinity
TimeoutStartSec=0
Restart=on-abnormal
KillMode=process[Install]
WantedBy=multi-user.target
[root@localhost ~]#
1.2 刷新配置重启docker
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl restart docker
docker-6027eda46ab74bdb30ec6de362d354161a8098af84f96938c667c1326418779c.scope docker.service
docker-cleanup.service docker-storage-setup.service
docker-cleanup.timer [root@localhost ~]# systemctl restart docker[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6027eda46ab7 registry "/entrypoint.sh /e..." About an hour ago Exited (2) 14 seconds ago liubijun_registry
8bec0ca04062 jdk1.8 "/bin/bash" About an hour ago Exited (2) About an hour ago myjdk8
894c19980c8d rabbitmq:management "docker-entrypoint..." 3 weeks ago Exited (0) 2 weeks ago liubijun_rabbitmq
89227b3809e8 mobz/elasticsearch-head:5 "/bin/sh -c 'grunt..." 3 weeks ago Exited (137) 2 weeks ago liubijun_es_head
c4de8f237ce0 elasticsearch:5.6.8 "/docker-entrypoin..." 3 weeks ago Exited (143) 2 weeks ago liubijun_el
6f1fc5d13f54 mongo "docker-entrypoint..." 4 months ago Exited (0) 2 weeks ago liubijun_mongo
3dbc64abd005 nginx "nginx -g 'daemon ..." 4 months ago Exited (255) 2 months ago 0.0.0.0:80->80/tcp liubijun_nginx
c34d96964e7e redis "docker-entrypoint..." 4 months ago Exited (0) 2 weeks ago liubijun_redis
cf0eefc03df7 tomcat "catalina.sh run" 4 months ago Exited (143) 5 weeks ago liubijun_tomcat
0a816c1be4f2 mysql "docker-entrypoint..." 4 months ago Exited (0) 2 hours ago liubijun_mysql
5660c3cb91bc centos "/bin/bash" 4 months ago Exited (255) 4 months ago mycentos2[root@localhost ~]# docker start 6027eda46ab7
6027eda46ab7
1.3 boot项目添加插件
<build><finalName>test</finalName><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin><!-- docker的maven插件,官网:‐maven‐plugin --><plugin><groupId>com.spotify</groupId><artifactId>docker-maven-plugin</artifactId><version>0.4.13</version><configuration><imageName>192.168.85.198:5000/${project.artifactId}:${project.version}</imageName><baseImage>jdk1.8</baseImage><entryPoint>["java", "-jar","/${project.build.finalName}.jar"]</entryPoint><resources><resource><targetPath>/</targetPath><directory>${project.build.directory}</directory><include>${project.build.finalName}.jar</include></resource></resources><dockerHost>http://192.168.85.198:2375</dockerHost></configuration></plugin></plugins></build>
1.5 使用mvn 命令打包上传docker
E:\work\IdeaProjects\boot_docker\docker-simple>mvn clean package docker:build -DpushImage
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building docker-simple 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ docker-simple ---
[INFO] Deleting E:\work\IdeaProjects\boot_docker\docker-simple\target
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:resources (default-resources) @ docker-simple ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ docker-simple ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to E:\work\IdeaProjects\boot_docker\docker-simple\target\classes
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:testResources (default-testResources) @ docker-simple ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory E:\work\IdeaProjects\boot_docker\docker-simple\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:testCompile (default-testCompile) @ docker-simple ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.21.0:test (default-test) @ docker-simple ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:3.0.2:jar (default-jar) @ docker-simple ---
[INFO] Building jar: E:\work\IdeaProjects\boot_docker\docker-simple\target\test.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:2.0.1.RELEASE:repackage (default) @ docker-simple ---
[INFO]
[INFO] --- docker-maven-plugin:0.4.13:build (default-cli) @ docker-simple ---
[INFO] Copying E:\work\IdeaProjects\boot_docker\docker-simple\target\test.jar -> E:\work\IdeaProjects\boot_docker\docker-simple\target\docker\test.jar
[INFO] Building image 192.168.85.198:5000/docker-simple:1.0-SNAPSHOT
Step 1/3 : FROM jdk1.8---> 88a34dbcd5f0
Step 2/3 : ADD /test.jar //---> 25a429618043
Removing intermediate container c5dbe420851c
Step 3/3 : ENTRYPOINT java -jar /test.jar---> Running in d64ba076eec7---> f12272eb7bd2
Removing intermediate container d64ba076eec7
Successfully built f12272eb7bd2
[INFO] Built 192.168.85.198:5000/docker-simple:1.0-SNAPSHOT
[INFO] Pushing 192.168.85.198:5000/docker-simple:1.0-SNAPSHOT
The push refers to a repository [192.168.85.198:5000/docker-simple]
7ce611130edf: Pushed
d6faa6f536ab: Mounted from jdk1.8
10cc74d0d651: Mounted from jdk1.8
d69483a6face: Mounted from jdk1.8
1.0-SNAPSHOT: digest: sha256:46ef0b6467c0dabfddb034821147ae4e0aa841fcf37b3a0224cb825ed26857ca size: 1161
null: null
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 13.554 s
[INFO] Finished at: 2019-09-12T13:02:59+08:00
[INFO] Final Memory: 53M/469M
[INFO] ------------------------------------------------------------------------E:\work\IdeaProjects\boot_docker\docker-simple>
1.6 私有仓库查询
1.7 宿主机检查
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.85.198:5000/docker-simple 1.0-SNAPSHOT f12272eb7bd2 About a minute ago 610 MB
192.168.85.198:5000/jdk1.8 latest 88a34dbcd5f0 2 hours ago 589 MB
jdk1.8 latest 88a34dbcd5f0 2 hours ago 589 MB
mynginx_1.0 latest 242f3c6e0f81 4 months ago 109 MB
docker.io/nginx latest 27a188018e18 4 months ago 109 MB
docker.io/tomcat latest 5a069ba3df4d 5 months ago 465 MB
docker.io/mongo latest b1c8142b3efc 5 months ago 410 MB
docker.io/zookeeper latest 2a7f6fc5c8a1 5 months ago 150 MB
docker.io/redis latest a55fbf438dfd 5 months ago 95 MB
docker.io/mysql latest 7bb2586065cd 5 months ago 477 MB
docker.io/centos latest 9f38484d220f 6 months ago 202 MB
docker.io/registry latest f32a97de94e1 6 months ago 25.8 MB
docker.io/lwieske/java-8 latest ac36fa5aed45 7 months ago 163 MB
rabbitmq management df80af9ca0c9 13 months ago 149 MB
elasticsearch 5.6.8 6c0bdf761f3b 18 months ago 570 MB
mobz/elasticsearch-head 5 b19a5c98e43b 2 years ago 824 MB
1.8 创建并启动容器
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.85.198:5000/docker-simple 1.0-SNAPSHOT f12272eb7bd2 About a minute ago 610 MB
192.168.85.198:5000/jdk1.8 latest 88a34dbcd5f0 2 hours ago 589 MB
jdk1.8 latest 88a34dbcd5f0 2 hours ago 589 MB
mynginx_1.0 latest 242f3c6e0f81 4 months ago 109 MB
docker.io/nginx latest 27a188018e18 4 months ago 109 MB
docker.io/tomcat latest 5a069ba3df4d 5 months ago 465 MB
docker.io/mongo latest b1c8142b3efc 5 months ago 410 MB
docker.io/zookeeper latest 2a7f6fc5c8a1 5 months ago 150 MB
docker.io/redis latest a55fbf438dfd 5 months ago 95 MB
docker.io/mysql latest 7bb2586065cd 5 months ago 477 MB
docker.io/centos latest 9f38484d220f 6 months ago 202 MB
docker.io/registry latest f32a97de94e1 6 months ago 25.8 MB
docker.io/lwieske/java-8 latest ac36fa5aed45 7 months ago 163 MB
rabbitmq management df80af9ca0c9 13 months ago 149 MB
elasticsearch 5.6.8 6c0bdf761f3b 18 months ago 570 MB
mobz/elasticsearch-head 5 b19a5c98e43b 2 years ago 824 MB[root@localhost ~]# docker run -id --name=liubijun_test -p 9004:9004 f12272eb7bd2 /bin/bash
5046223f7bd9af5d4c45eb932097ab07611933943d915e3ea6ce2df34c78e71d
[root@localhost ~]#
1.9 测试
更多推荐
idea springboot docker 私有仓库联动
发布评论