一、安装docker:
二、安装docker私服
# 拉取镜像
docker pull registry
# 运行registry
docker run -d -p 5000:5000 -v /Users/chenfenli/Bin/kubernetes/docker-registry:/var/lib/registry registry
# 查看容器
MacBook-Air:kubernetes chenfenli$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a89831f936f3 registry "/entrypoint.sh /etc…" 31 seconds ago Up 10 seconds 0.0.0.0:5000->5000/tcp, :::5000->5000/tcp crazy_williams
访问地址:http://127.0.01:5000/v2/_catalog
三、使用Dockerfile创建镜像
- 使用maven工具创建docker-demo项目,yml:
server:
port: 9010
servlet:
context-path: /
@RestController
@RequestMapping("/login/")
public class LoginController {
@RequestMapping("to_login")
public Object toLogin(String username, String password) {
return "username: " + username + " password: " + password;
}
}
- dockerfile-maven-plugin 和 Dockerfile:Dockerfile和pom在同级目录下
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.4.10</version>
<executions>
<execution>
<id>default</id>
<goals>
<goal>build</goal>
<goal>push</goal>
</goals>
</execution>
</executions>
<configuration>
<repository>127.0.0.1:5000/${project.artifactId}</repository>
<tag>${project.version}</tag>
<buildArgs>
<JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
</configuration>
</plugin>
</plugins>
</build>
FROM openjdk:8u191-jre-alpine3.9
EXPOSE 9010
ARG JAR_FILE
ADD ${JAR_FILE} /app.jar
ENTRYPOINT ["java", "-jar","/app.jar"]
MacBook-Air:docker-demo-admin chenfenli$ mvn clean package
...
Downloaded: http://jcenter.bintray.com/com/fasterxml/jackson/module/jackson-module-jaxb-annotations/2.9.6/jackson-module-jaxb-annotations-2.9.6.jar (0 B at 0.0 KB/sec)
[INFO] dockerfile: null
[INFO] contextDirectory: /Users/chenfenli/Documents/work_idea/docker-demo/docker-demo-admin
[INFO] Building Docker context /Users/chenfenli/Documents/work_idea/docker-demo/docker-demo-admin
[INFO] Path(dockerfile): null
[INFO] Path(contextDirectory): /Users/chenfenli/Documents/work_idea/docker-demo/docker-demo-admin
[INFO]
[INFO] Image will be built as 127.0.0.1:5000/docker-demo-admin:1.0
[INFO]
[INFO] Step 1/5 : FROM openjdk:8u191-jre-alpine3.9
[INFO]
[INFO] Pulling from library/openjdk
[INFO] Digest: sha256:f7ea122d42799223ea01231d2661fd95a2695d6085ba57d6378b68463247011d
[INFO] Status: Image is up to date for openjdk:8u191-jre-alpine3.9
[INFO] ---> b76bbdb2809f
[INFO] Step 2/5 : EXPOSE 9010
[INFO]
[INFO] ---> Running in 67ca0a61f847
[INFO] Removing intermediate container 67ca0a61f847
[INFO] ---> 5bab4acbe8e2
[INFO] Step 3/5 : ARG JAR_FILE
[INFO]
[INFO] ---> Running in 4f705daf7078
[INFO] Removing intermediate container 4f705daf7078
[INFO] ---> 9975bf01dcf5
[INFO] Step 4/5 : ADD ${JAR_FILE} /app.jar
[INFO]
[INFO] ---> 573f19dd6335
[INFO] Step 5/5 : ENTRYPOINT ["java", "-jar","/app.jar"]
[INFO]
[INFO] ---> Running in 3efb12889cec
[INFO] Removing intermediate container 3efb12889cec
[INFO] ---> 4fdd2eb136b2
[INFO] Successfully built 4fdd2eb136b2
[INFO] Successfully tagged 127.0.0.1:5000/docker-demo-admin:1.0
[INFO]
[INFO] Detected build of image with id 4fdd2eb136b2
[INFO] Building jar: /Users/chenfenli/Documents/work_idea/docker-demo/docker-demo-admin/target/docker-demo-admin-1.0-docker-info.jar
[INFO] Successfully built 127.0.0.1:5000/docker-demo-admin:1.0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:02.816s
[INFO] Finished at: Mon Jul 12 23:24:49 CST 2021
[INFO] Final Memory: 37M/312M
[INFO] ------------------------------------------------------------------------
MacBook-Air:docker-demo-admin chenfenli$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
127.0.0.1:5000/docker-demo-admin 1.0 4fdd2eb136b2 39 seconds ago 102MB
127.0.0.1:5000/docker-demo 1.0 6a94096cc5a4 24 hours ago 102MB
四、将镜像推送到私服
MacBook-Air:docker-demo-admin chenfenli$ docker push 127.0.0.1:5000/docker-demo-admin:1.0
The push refers to repository [127.0.0.1:5000/docker-demo-admin]
3fe7acaa1fff: Pushed
925523484e00: Mounted from docker-demo
344fb4b275b7: Mounted from docker-demo
bcf2f368fe23: Mounted from docker-demo
1.0: digest: sha256:0cd2117d6817e2df5d19a343b702c760d8932f59eb1e0912639102d6d537d77d size: 1159
MacBook-Air:docker-demo-admin chenfenli$
|