準(zhǔn)備工作
開啟遠(yuǎn)程端口
docker服務(wù)器上
1.直接在公有倉(cāng)庫(kù)拉取倉(cāng)庫(kù)的鏡像
docker pull registry
2.修改docker配置
vim /usr/lib/systemd/system/docker.service
ExecStart 添加 -H tcp://0.0.0.0:2375
添加后如下
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
BindsTo=containerd.service
After=network-online.target firewalld.service containerd.service
Wants=network-online.target
Requires=docker.socket
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd --insecure-registry 0.0.0.0:5000 -H tcp://0.0.0.0:2375 -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always
# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3
# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
TasksMax=infinity
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
[Install]
WantedBy=multi-user.target
重新加載配置文件重啟
systemctl daemon-reload
systemctl restart docker
maven配置:
無(wú)需yml的pom.xml配置
<build>
<plugins>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.13</version>
<configuration>
<forceTags>true</forceTags> <!--覆蓋相同標(biāo)簽鏡像-->
<imageName>my/eureka:0.0.1</imageName> <!--指定鏡像名稱 倉(cāng)庫(kù)/鏡像名:標(biāo)簽-->
<baseImage>lwieske/java-8</baseImage> <!--指定基礎(chǔ)鏡像,相當(dāng)于dockerFile中的FROM<image> -->
<dockerHost>http://192.168.10.72:2375</dockerHost> <!-- 指定倉(cāng)庫(kù)地址 -->
<entryPoint>["java","-jar","/${project.build.finalName}.jar"]</entryPoint> <!-- 容器啟動(dòng)執(zhí)行的命令,相當(dāng)于dockerFile的ENTRYPOINT -->
<resources>
<resource> <!-- 指定資源文件 -->
<targetPath>/</targetPath> <!-- 指定要復(fù)制的目錄路徑,這里是當(dāng)前目錄 -->
<directory>${project.build.directory}</directory> <!-- 指定要復(fù)制的根目錄,這里是target目錄 -->
<include>${project.build.finalName}.jar</include> <!-- 指定需要拷貝的文件,這里指最后生成的jar包 -->
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
需要yml的pom文件配置
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.13</version>
<configuration>
<forceTags>true</forceTags> <!--覆蓋相同標(biāo)簽鏡像-->
<imageName>my/eureka:0.0.2</imageName> <!--指定鏡像名稱 倉(cāng)庫(kù)/鏡像名:標(biāo)簽-->
<dockerHost>http://192.168.10.73:2375</dockerHost> <!-- 指定倉(cāng)庫(kù)地址 -->
<dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory> <!--dockerfile文件路徑-->
<resources>
<resource> <!-- 指定資源文件 -->
<targetPath>/</targetPath> <!-- 指定要復(fù)制的目錄路徑,這里是當(dāng)前目錄 -->
<directory>${project.build.directory}</directory> <!-- 指定要復(fù)制的根目錄,這里是target目錄 -->
<include>${project.build.finalName}.jar</include> <!-- 指定需要拷貝的文件,這里指最后生成的jar包 -->
</resource>
</resources>
</configuration>
</plugin>
maven 發(fā)布
重點(diǎn)?。。?!
鏡像名稱一定不能有大寫字母
因?yàn)殓R像名稱取的是項(xiàng)目名稱,而項(xiàng)目名稱有大寫英文字母導(dǎo)致鏡像一直上傳失敗提示:Broken pipe (Write failed)
在maven中配置名稱小寫就上傳成功了
clean package docker:build