docker configure CentOS 7 in Docker installation and project

CentOS 7 mounted in Docker

 

 

 

卸载旧版本(如果安装过旧版本的话)

sudo yum remove docker \
                docker-client \
                docker-client-latest \
                docker-common \
                docker-latest \
                docker-latest-logrotate \
                docker-logrotate \
                docker-selinux \
                docker-engine-selinux \
                docker-engine
#更新 yum 
yum -y update
​
#安装 docker
yum -y install docker
​
#进入 docker
vi /etc/sysconfig/docker
​
# 修改 --selinux-enabled=false 
​
# /etc/sysconfig/docker
​
# Modify these options if you want to change the way the docker daemon runs
OPTIONS='--selinux-enabled=false --log-driver=journald --signature-verification=false'
if [ -z "${DOCKER_CERT_PATH}" ]; then
    DOCKER_CERT_PATH=/etc/docker
fi
​
# :wq 退出保存
# 重新启动 docker
systemctl restart docker 
​
docker version
​
Client:
 Version:         1.13.1
 API version:     1.26
 Package version: docker-1.13.1-63.git94f4240.el7.centos.x86_64
 Go version:      go1.9.4
 Git commit:      94f4240/1.13.1
 Built:           Fri May 18 15:44:33 2018
 OS/Arch:         linux/amd64
​
Server:
 Version:         1.13.1
 API version:     1.26 (minimum version 1.12)
 Package version: docker-1.13.1-63.git94f4240.el7.centos.x86_64
 Go version:      go1.9.4
 Git commit:      94f4240/1.13.1
 Built:           Fri May 18 15:44:33 2018
 OS/Arch:         linux/amd64
 Experimental:    false

Open the Remote API

# 编辑该文件
vi /etc/sysconfig/docker-network
​
# /etc/sysconfig/docker-network  找到 DOCKER_NETWORK_OPTIONS, 补全
DOCKER_NETWORK_OPTIONS="-H unix:///var/run/docker.sock -H 0.0.0.0:5555"  
​
#然后重启docker
sudo systemctl daemon-reload
sudo service docker restart
​
​
# :wq 强制保存 在使用netstat 查看该端口
netstat -anp|grep 5555
​
#查看该应用
curl 127.0.0.1:5555/info
~~~

~~~

#关闭防火墙 因为开了防火墙无法访问
#临时关闭
systemctl stop firewalld
#禁止开机启动
systemctl disable firewalld

Using docker way to package server

1. In the pom.xml file to the corresponding plug (ps: docker.image.prefix name refers to the warehouse, it is recommended to use the name dockerhub otherwise not be able to submit to push its own warehouse owenwangwen)

<properties>
  <docker.image.prefix>owenwangwen</docker.image.prefix>
</properties>
​
<plugin>
  <groupId>com.spotify</groupId>
  <artifactId>docker-maven-plugin</artifactId>
  <version>0.4.13</version>
  <configuration>
    <imageName>${docker.image.prefix}/${project.artifactId}</imageName>
    <dockerDirectory>src/main/docker</dockerDirectory>
    <!-- docker远程服务器地址 -->
    <dockerHost>http://xx.xx.xx.xx:5555</dockerHost>
    <resources>
      <resource>
        <targetPath>/</targetPath>
        <directory>${project.build.directory}</directory>
        <include>${project.build.finalName}.jar</include>
      </resource>
    </resources>
  </configuration>
</plugin>

Using docker way to package server

2. Create a new package docker each module in the src / main Next, in the new Dockerfile src / main / below docker

Dockerfile file

FROM openjdk:8-jdk-alpine
VOLUME /tmp
ADD user-center.jar app.jar
RUN sh -c 'touch /app.jar'
ENV JAVA_OPTS=""
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]

Note: Note that (app.jar means that the project packaged jar)

Explanation:

FROM point to container name openjdk need to create: 8-jdk-alpine (in addition to the notes, must be the first line of writing, otherwise an error)

tag did not write the default fetch latest, may be considered to be the version number

ADD (add files to the vessel, the host files, network files, folders)

VOLUME (mount point, a host of other containers)

RUN (command for modifying the mirror, commonly installed library program, and a program configuration)

ENV (set the environment variable container)

CMD (start command default container)

EntryPoint (similar to the CMD, CMD used in conjunction with)
item packaged into mirror

Sample

  • Configuring docker host address

  • docker: build mirrored host docker upload

  • docker: build process is mirrored

  • Login host View Mirror

  • docker login

  • Upload hub.docker

[root@localhost ~]# docker push owenwangwen/eureka-server

 

 

Published 11 original articles · won praise 0 · Views 170

Guess you like

Origin blog.csdn.net/sdjxgd/article/details/105200022