搭建環境
winds7 和 Centos 7.7中Docker安裝方法
1.docker環境安裝
這裏推薦使用yum安裝,離線環境可以下載 Centos7 的全鏡像 iOS 包掛載到yum
yum install -y docker
安裝完成即可
查看相關目錄
rom -ql docker
配置環境目錄
/etc/docker/daemon.json 爲配置文件
"registry-mirrors":["https://lq7fh6ix.mirror.aliyuncs.com"], 遠程鏡像加速
"hosts":["tcp://0.0.0.0:2376","unix:///var/run/docker.sock"] docker監聽服務 API 開啓,便於遠程連接操作 "
insecure-registries": [] 私有倉庫地址
參考網頁:https://docs.docker.com/engine/reference/commandline/dockerd/#daemon-configuration-file
/var/lib/docker 爲鏡像,容器存放地點
下面目錄內容:
overlay驅動只能工作在兩層之上。也就是說多層鏡像不能用多層OverlayFS實現。替代的,每個鏡像層在/var/lib/docker/overlay中用自己的目錄來實現,使用硬鏈接這種有效利用空間的方法,來引用底層分享的數據。注意:Docker1.10之後,鏡像層ID和/var/lib/docker中的目錄名不再一一對應。
創建一個容器,overlay驅動聯合鏡像層和一個新目錄給容器。鏡像頂層是overlay中的只讀lowerdir,容器的新目錄是可寫的upperdir。
/var/lib/docker/overlay
網上查一下這個目錄的作用,說是 overlay/overlay2表示Docker的存儲驅動,可以參考一下這篇文章:https://blog.csdn.net/styshoo/article/details/60715942
也就是說容器/鏡像等都會存在這個目錄下,當量大的時候就會佔滿硬盤。
也可以參考官網(https://docs.docker.com/storage/storagedriver/overlayfs-driver/)
使用 docker system prune來自動清理空間,
- 該指令默認會清除所有如下資源:
- 已停止的容器(container)
- 未被任何容器所使用的卷(volume)
- 未被任何容器所關聯的網絡(network)
- 所有懸空鏡像(image)。
- 該指令默認只會清除懸空鏡像,未被使用的鏡像不會被刪除。
- 添加
-a 或 --all
參數後,可以一併清除所有未使用的鏡像和懸空鏡像。 - 可以添加
-f 或 --force
參數用以忽略相關告警確認信息。 - 指令結尾處會顯示總計清理釋放的空間大小。
以上爲docker 安裝
eclipse 需要 安裝IDE 插件在超市中 搜 docker-tools安裝
配置鏡像選擇TCP 連接
3。使用docker maven plugin,這裏需要安裝maven 不做多介紹
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<!-- since 2.0 -->
<version>3.7.0</version>
<configuration>
<!-- use the Java 8 language features -->
<source>1.8</source>
<!-- want the compiled classes to be compatible with JVM 1.8 -->
<target>1.8</target>
<!-- The -encoding argument for the Java compiler. -->
<encoding>UTF8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.13</version>
<configuration>
<imageName>mavendemo</imageName>
<baseImage>java8</baseImage>
<!-- <maintainer>docker_maven [email protected]</maintainer> <workdir>/ROOT</workdir> -->
<cmd>["java", "-version"]</cmd>
<!-- 注意imageName一定要是符合正則[a-z0-9-_.]的,否則構建不會成功 -->
<!-- 詳見:https://github.com/spotify/docker-maven-plugin Invalid repository
name ... only [a-z0-9-_.] are allowed -->
<entryPoint>["java", "-jar", "${project.build.finalName}.jar"]</entryPoint>
<!-- 這裏是複製 jar 包到 docker 容器指定目錄配置 -->
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
注意:<dockerHost>tcp://ip:2376<dockerHost> 可以作爲環境變量配置,或者eclipse臨時環境變量。
參考文檔:https://github.com/spotify/docker-maven-plugin