开发者社区> han1396735592> 正文
阿里云
为了无法计算的价值
打开APP
阿里云APP内打开

JAVA项目发布到docker

简介: JAVA项目发布到docker
+关注继续查看

第一步:打开docker远程API端口

​ 我的是centos7系统,需要修改的文件是/usr/lib/systemd/system/docker.service 文件

vim /usr/lib/systemd/system/docker.service 

如下是我的配置文件,需要添加的部分是在第13-17行:ExecStart=/usr/bin/dockerd的后面加上-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock,ok之后 :wq ,保存并退出。注意的是0.0.0.0,你没看错,这样配置就行,并不是自己的主机ip

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target

[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

#start add config

ExecStart=/usr/bin/dockerd  -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock

#end
ExecReload=/bin/kill -s HUP $MAINPID
# 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
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# 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
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s

[Install]
WantedBy=multi-user.target

第二步:重启docker的守护进程,重启docker

命令如下:

systemctl daemon-reload

systemctl restart docker

输入netstat -anp|grep 2375 显示docker正在监听2375端口

[root@izjmd5lqoeeowpz ~]# netstat -anp|grep 2375
tcp6       0      0 :::2375                 :::*                    LISTEN      2577/dockerd

输入curl 127.0.0.1:2375/info 显示一大堆信息,证明端口已经对外开放了

{"ID":"5ZCY:OFMV:ZO4J:WMQ2:OW57:76PX:VSF2:YX6W:6NKU:3YK6:5WJX:P7BT","Containers":0,"ContainersRunning":0,"ContainersPaused":0,"ContainersStopped":0,"Images":0,"Driver":"overlay2","DriverStatus":[["Backing Filesystem","extfs"],["Supports d_type","true"],["Native Overlay Diff","false"]],"SystemStatus":null,"Plugins":{"Volume":["local"],"Network":["bridge","host","macvlan","null","overlay"],"Authorization":null,"Log":["awslogs","fluentd","gcplogs","gelf","journald","json-file","logentries","splunk","syslog"]},"MemoryLimit":true,"SwapLimit":true,"KernelMemory":true,"CpuCfsPeriod":true,"CpuCfsQuota":true,"CPUShares":true,"CPUSet":true,"IPv4Forwarding":true,"BridgeNfIptables":true,"BridgeNfIp6tables":true,"Debug":false,"NFd":24,"OomKillDisable":true,"NGoroutines":44,"SystemTime":"2018-10-01T16:31:00.417378358+08:00","LoggingDriver":"json-file","CgroupDriver":"cgroupfs","NEventsListener":0,"KernelVersion":"3.10.0-514.26.2.el7.x86_64","OperatingSystem":"CentOS Linux 7 (Core)","OSType":"linux","Architecture":"x86_64","IndexServerAddress":"https://index.docker.io/v1/","RegistryConfig":{"AllowNondistributableArtifactsCIDRs":[],"AllowNondistributableArtifactsHostnames":[],"InsecureRegistryCIDRs":["127.0.0.0/8"],"IndexConfigs":{"docker.io":{"Name":"docker.io","Mirrors":[],"Secure":true,"Official":true}},"Mirrors":[]},"NCPU":1,"MemTotal":1928933376,"GenericResources":null,"DockerRootDir":"/var/lib/docker","HttpProxy":"","HttpsProxy":"","NoProxy":"","Name":"izjmd5lqoeeowpz","Labels":[],"ExperimentalBuild":false,"ServerVersion":"18.06.1-ce","ClusterStore":"","ClusterAdvertise":"","Runtimes":{"runc":{"path":"docker-runc"}},"DefaultRuntime":"runc","Swarm":{"NodeID":"","NodeAddr":"","LocalNodeState":"inactive","ControlAvailable":false,"Error":"","RemoteManagers":null},"LiveRestoreEnabled":false,"Isolation":"","InitBinary":"docker-init","ContainerdCommit":{"ID":"468a545b9edcd5932818eb9de8e72413e616e86e","Expected":"468a545b9edcd5932818eb9de8e72413e616e86e"},"RuncCommit":{"ID":"69663f0bd4b60df09991c08812a60108003fa340","Expected":"69663f0bd4b60df09991c08812a60108003fa340"},"InitCommit":{"ID":"fec3683","Expected":"fec3683"},"SecurityOptions":["name=seccomp,profile=default"]}

第三步:创建一个springboot项目

start.spring.io

第四步: 添加插件docker-maven-plugin

<plugin>
    <groupId>com.spotify</groupId>
    <artifactId>docker-maven-plugin</artifactId>
    <version>1.0.0</version>
    <configuration>
        <imageName>${docker.image.prefix}-${project.artifactId}</imageName>
        <!--<dockerDirectory>src/main/docker</dockerDirectory>-->
        <baseImage>java</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>
    </configuration>
</plugin>

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
什么,容器太多操作不过来?我选择Docker Compose梭哈(下)
什么,容器太多操作不过来?我选择Docker Compose梭哈(下)
648 0
架构师之路 -- 虚拟化技术与容器Docker
通常架构师们为了提高系统及硬件资源的利用率引入了虚拟化技术。
137 0
Docker容器基础(二) - Docker公司的入场
Docker容器基础(二) - Docker公司的入场
57 0
Docker容器实战(四) - 纷纷扰扰,终归尘土(上)
Docker容器实战(四) - 纷纷扰扰,终归尘土(上)
98 0
Docker容器实战(四) - 纷纷扰扰,终归尘土(中)
Docker容器实战(四) - 纷纷扰扰,终归尘土(中)
86 0
Docker容器实战(四) - 纷纷扰扰,终归尘土(下)
Docker容器实战(四) - 纷纷扰扰,终归尘土(下)
91 0
Docker容器实战(六) - Docker是如何实现隔离的?(上)
Docker容器实战(六) - Docker是如何实现隔离的?(上)
146 0
Docker容器实战(六) - Docker是如何实现隔离的?(下)
Docker容器实战(六) - Docker是如何实现隔离的?(下)
38 0
Docker容器实战(七) - Docker存储隔离原理?(上)
Docker容器实战(七) - Docker存储隔离原理?(上)
78 0
Docker容器实战(七) - Docker存储隔离原理?(下)
Docker容器实战(七) - Docker存储隔离原理?(下)
105 0
+关注
文章
问答
文章排行榜
最热
最新
相关电子书
更多
我的Docker:Docker插件机制详解
立即下载
阿里特邀专家徐雷Java Spring Boot开发实战系列课程(第18讲):制作Java Docker镜像与推送到DockerHub和阿里云Docker仓库
立即下载
基于Docker on Yarn系统的微服务实践
立即下载