docker使用maven构建远程镜像

1.应用环境

  • 默认docker服务启动 文件(/usr/lib/systemd/system/docker.service) vi 编辑文件

  • 在ExecStart后面 添加一行(表示启动2375端口 用于监听远程操作)

-H tcp://0.0.0.0:2375  -H unix:///var/run/docker.sock \
[root@localhost docker]# vi /usr/lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=http://docs.docker.com
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 \
          -H tcp://0.0.0.0:2375  -H unix:///var/run/docker.sock \     //插入远程端口
          $OPTIONS \
          $DOCKER_STORAGE_OPTIONS \
          $DOCKER_NETWORK_OPTIONS \
          $ADD_REGISTRY \
          $BLOCK_REGISTRY \
          $INSECURE_REGISTRY \
          $REGISTRIES
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=1048576
LimitNPROC=1048576
LimitCORE=infinity
TimeoutStartSec=0
Restart=on-abnormal
KillMode=process

[Install]
WantedBy=multi-user.target
~
"/usr/lib/systemd/system/docker.service" 41L, 1309C
  • 重新加载
[root@localhost docker]# systemctl daemon-reload 

2.使用dockerfile-maven-plugin插件远程构建docker

  • 环境变量设置
    docker使用maven构建远程镜像_第1张图片

  • maven项目pom.xml配置


	NginxExLinux     //maven指定package包名
        
            
                com.spotify
                dockerfile-maven-plugin
                1.4.0
                
                    NginxExLinux
                    1
                    
                        target/${project.build.finalName}.jar
                    
                
            
        

  • Dockerfile 文件配置(项目目录下)
    将maven项目打包的target目录下的 NginxExLinux.war 拷贝到tomcat容器下的 /usr/local/tomcat/webapps 目录
FROM tomcat
COPY target/NginxExLinux.war /usr/local/tomcat/webapps
  • 执行生成镜像
mvn clean package dockerfile:build -DskipTests
  • 报下列错误时,需将Dockerfile文件放置在maven项目根目录下
[ERROR] Missing Dockerfile in context directory: E:\eclipse-workspace-server\NginxExLinux
  • 错误//Could not build image不能创建镜像,原因是eclipse中的cmd 不读取环境变量
Caused by: java.util.concurrent.ExecutionException: com.spotify.docker.client.shaded.javax.ws.rs.ProcessingException: com.
spotify.docker.client.shaded.org.apache.http.conn.HttpHostConnectException: Connect to localhost:2375 [localhost/127.0.0.1
, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect

//解决方法 可通过Windows的cmd 实现 执行生成镜像

docker使用maven构建远程镜像_第2张图片

你可能感兴趣的:(Linux,Docker,Maven)