-
开放docker远程访问:
vi /lib/systemd/system/docker.service
在ExecStart=/usr/bin/dockerd -H 后面添加 tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock
- 刷新配置,重启服务:
systemctl daemon-reload
systemctl restart docker
docker start registry - idea pox.xml中配置:
<build>
<finalName>app</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
</plugin>
<!--docker的maven插件-->
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.13</version>
<configuration>
<!--配置docker的镜像工程-->
<imageName>47.95.228.162:5001/${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://47.95.228.162:2375</dockerHost>
</configuration>
</plugin>
</plugins>
</build>
- idea打包上传镜像到服务器:(服务器上docker的远程连接端口一定要开放)
mvn install
mvn docker:build -DpushImage - 服务器上查看:
docker images - 浏览器查看:
http://47.95.228.162:5001/v2/_catalog
- 服务器上启动镜像
docker run -di --name=wordpress -p 8099:8099 47.95.228.162:5001/wordpressport:0.0.1-SNAPSHOT
[root@iz2zegpdc9x4o0ir42a2upz ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
47.95.228.162:5001/wordpressport 0.0.1-SNAPSHOT 42610e023c13 5 minutes ago 638MB
47.95.228.162:5001/jdk1.8 latest b5984b02f4fb 5 hours ago 589MB
jdk1.8 latest b5984b02f4fb 5 hours ago 589MB
redis latest f7302e4ab3a8 41 hours ago 98.2MB
nginx latest 4733136e5c3c 2 days ago 126MB
tomcat 7-jre7 47c156f4d4e3 3 months ago 359MB
centos/mysql-57-centos7 latest e35b3f7a4ea0 4 months ago 452MB
centos 7 9f38484d220f 5 months ago 202MB
registry latest f32a97de94e1 5 months ago 25.8MB
tutum/centos latest 99a633ad346f 3 years ago 297MB
[root@iz2zegpdc9x4o0ir42a2upz ~]# docker run -di --name=wordpress -p 8099:8099 47.95.228.162:5001/wordpressport:0.0.1-SNAPSHOT
196d7e96b986c148c361d269f9bf51b495da91987dcf14a7f7e90b6dc8073d24
[root@iz2zegpdc9x4o0ir42a2upz ~]#
- 查看jar包是否运行
[root@iz2zegpdc9x4o0ir42a2upz ~]# ps -aux|grep .jar
root 224207 0.3 10.5 1470276 107212 ? Ssl 14:52 0:05 /docker-java-home/jre/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Dignore.endorsed.dirs= -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start
root 226452 23.5 18.5 2256384 188908 ? Ssl 15:16 0:26 java -jar /app.jar
root 226627 0.0 0.0 112708 1008 pts/0 R+ 15:17 0:00 grep --color=auto .jar
已发现app.jar在运行,打开浏览器输入访问接口,测试是否开放了访问端口
- 查看日志文件
docker logs -f 容器ID/容器名
例如: docker logs -f wordpress