Linux -- 搭建 docker 私服

1、服务器 -- 安装 docker

参考  https://blog.csdn.net/sky_eyeland/article/details/101200959

2、服务器 -- 安装 docker-registry

  • docker-compose.yml
version: "3"

services:
  registry:
    image: docker.io/registry
    ports:
      - "5000:5000"
    volumes:
      - "/usr/local/work/docker/registry:/var/lib/registry"
    container_name: registry
    privileged: true
  • 开启 tcp 2375 端口
# 编辑文件
vim /lib/systemd/system/docker.service

# 修改内容,改为
ExecStart=/usr/bin/dockerd-current -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock \
  • 重启 docker
systemctl daemon-reload && systemctl restart docker
  • 重启 docker-registry
docker start 2e

3、查看启动状态

systemctl status docker
docker ps -a
lsof -i:2375

4、maven 项目配置 -- jar 方式

  • 创建目录
# 创建目录
src/main/docker

# 添加 Dockfile 文件
FROM daocloud.io/library/java:openjdk-8u40-jdk
MAINTAINER vim
VOLUME /tmp
ARG JAR_FILE
ADD ${JAR_FILE} app.jar
ENV JAVA_OPTS=""
ENTRYPOINT ["sh","-c","java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar"]
  • maven 配置 
<properties>
  <docker.registry>192.168.147.130:5000</docker.registry>
</properties>

<plugin>
  <groupId>com.spotify</groupId>
  <artifactId>docker-maven-plugin</artifactId>
  <version>0.4.13</version>
  <executions>
    <execution>
      <id>build-image</id>
      <phase>package</phase>
      <goals>
        <goal>build</goal>
      </goals>
    </execution>
   <!-- <execution>
      <id>push-image</id>
      <phase>package</phase>
      <goals>
        <goal>push</goal>
      </goals>
    </execution>-->
  </executions>
  <configuration>
    <imageName>${docker.registry}/${project.name}:${project.version}</imageName>
    <imageTags>
      <imageTag>${project.version}</imageTag>
      <imageTag>latest</imageTag>
    </imageTags>
    <forceTags>true</forceTags>
    <dockerDirectory>src/main/docker</dockerDirectory>
    <resources>
      <resource>
        <targetPath>/</targetPath>
        <directory>${project.build.directory}</directory>
        <include>${project.build.finalName}.jar</include>
      </resource>
    </resources>
    <buildArgs>
      <JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
    </buildArgs>
    <dockerHost>http://192.168.147.130:2375</dockerHost>
  </configuration>
</plugin>
  • 运行容器
systemctl start firewalld

docker run --name demo -p "8081:8081" -d 192.168.147.130:5000/demo

systemctl stop firewalld

 

6、maven 项目配置 -- war 方式

  • 创建目录
FROM daocloud.io/library/tomcat:8.5.15-jre8
MAINTAINER vim

WORKDIR /usr/local/tomcat/webapps
ARG JAR_FILE
ADD ${JAR_FILE} ${JAR_FILE}
  • maven 配置,参考 springboot war 打包方式镜像配置 
<plugin>
  <groupId>com.spotify</groupId>
  <artifactId>docker-maven-plugin</artifactId>
  <version>0.4.13</version>
  <executions>
    <execution>
      <id>build-image</id>
      <phase>package</phase>
      <goals>
        <goal>build</goal>
      </goals>
    </execution>
   <!-- <execution>
      <id>push-image</id>
      <phase>package</phase>
      <goals>
        <goal>push</goal>
      </goals>
    </execution>-->
  </executions>
  <configuration>
    <imageName>${docker.registry}/${project.name}:${project.version}</imageName>
    <imageTags>
      <imageTag>${project.version}</imageTag>
      <imageTag>latest</imageTag>
    </imageTags>
    <forceTags>true</forceTags>
    <dockerDirectory>src/main/docker</dockerDirectory>
    <resources>
      <resource>
        <targetPath>/</targetPath>
        <directory>${project.build.directory}</directory>
        <include>${project.build.finalName}.war</include>
      </resource>
    </resources>
    <buildArgs>
      <JAR_FILE>${project.build.finalName}.war</JAR_FILE>
    </buildArgs>
    <dockerHost>http://192.168.147.130:2375</dockerHost>
  </configuration>
</plugin>
  • 运行容器
systemctl start firewalld

docker run --name tomcat -p "8083:8080" -d 192.168.147.130:5000/demo

systemctl stop firewalld

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值