Docker实战笔记 三 Docker私有库

1.拉取私有库image

[email protected]:/root#docker pull registry
Using default tag: latest
latest: Pulling from library/registry
c926b61bad3b: Pull complete 
5501dced60f8: Pull complete 
e875fe5e6b9c: Pull complete 
21f4bf2f86f9: Pull complete 
98513cca25bb: Pull complete 
Digest: sha256:0a182cb82c93939407967d6d71d6caf11dcef0e5689c6afe2d60518e3b34ab86
Status: Downloaded newer image for registry:latest
docker.io/library/registry:latest
[email protected]:/root#docker images
REPOSITORY             TAG                IMAGE ID       CREATED         SIZE
hello                  1.0                7e8f5c344014   4 days ago      545MB
registry               latest             909c3ff012b7   5 days ago      25.4MB
postgres               12                 0d56839ac0df   3 weeks ago     412MB
redis                  latest             7c4b517da47d   3 months ago    153MB
openzipkin/zipkin      latest             7fb470c13693   4 months ago    165MB
postgres               latest             1921dda0e2c5   5 months ago    412MB
redis                  6.2.10-alpine      a470c0525301   9 months ago    27.1MB
sonarqube              8.9.10-community   4009139ebd19   11 months ago   490MB
openjdk                8                  b273004037cc   16 months ago   526MB
seataio/seata-server   1.5.2              f6a5368b6720   17 months ago   186MB
nacos/nacos-server     2.0.3              433eb51fef8d   2 years ago     1.05GB
seataio/seata-server   1.4.2              4909c4c024dc   2 years ago     156MB
training/webapp        latest             6fae60ef3446   8 years ago     349MB

2.启动私有库

[email protected]:/root#docker run -d -p 5000:5000 -v /home/my_registry/:/tmp/registry --privileged=true registry
425777c5079d3f66d6b0acdd75dfeb218a11e6089e9dedce33693d68887231b7
[email protected]:/root#docker ps
CONTAINER ID   IMAGE                        COMMAND                   CREATED         STATUS         PORTS                                                                                  NAMES
425777c5079d   registry                     "/entrypoint.sh /etc…"   5 seconds ago   Up 4 seconds   0.0.0.0:5000->5000/tcp, :::5000->5000/tcp                                              youthful_almeida
a1205f118039   training/webapp              "python app.py"           19 hours ago    Up 2 hours     0.0.0.0:32770->5000/tcp, :::32769->5000/tcp                                            priceless_saha
b519a26da37b   7e8f5c344014                 "java -jar app.jar"       4 days ago      Up 4 days      0.0.0.0:9966->9933/tcp                                                                 hello
be0f46c5450a   seataio/seata-server:1.4.2   "java -Djava.securit…"   4 months ago    Up 4 days      0.0.0.0:8091->8091/tcp, :::8091->8091/tcp                                              seata-server
e5e9b616802c   nacos/nacos-server:2.0.3     "bin/docker-startup.…"   5 months ago    Up 4 days      0.0.0.0:8848->8848/tcp, :::8848->8848/tcp, 0.0.0.0:9848->9848/tcp, :::9848->9848/tcp   nacos203
85c7e7acf404   redis:6.2.10-alpine          "docker-entrypoint.s…"   9 months ago    Up 4 days      0.0.0.0:56379->6379/tcp, :::56379->6379/tcp                                            redis6.2
[email protected]:/home#cd my_registry/
[email protected]:/home/my_registry#ll
总用量 0

3.commit自定义镜像到私有库

[email protected]:/home/my_registry#docker commit -m="hello init" -a="hello docker" hello hello:v1
sha256:655f86577fb217adbda60901be0a92177451f26cce4eb0112750593f1291b933
[email protected]:/home/my_registry#docker images
REPOSITORY             TAG                IMAGE ID       CREATED              SIZE
hello                  v1                 655f86577fb2   2 seconds ago        545MB
hello                  1.0                cbe82fdf9fe1   About a minute ago   545MB
registry               latest             909c3ff012b7   5 days ago           25.4MB
postgres               12                 0d56839ac0df   3 weeks ago          412MB
redis                  latest             7c4b517da47d   3 months ago         153MB
openzipkin/zipkin      latest             7fb470c13693   4 months ago         165MB
postgres               latest             1921dda0e2c5   5 months ago         412MB
redis                  6.2.10-alpine      a470c0525301   9 months ago         27.1MB
sonarqube              8.9.10-community   4009139ebd19   11 months ago        490MB
openjdk                8                  b273004037cc   16 months ago        526MB
seataio/seata-server   1.5.2              f6a5368b6720   17 months ago        186MB
nacos/nacos-server     2.0.3              433eb51fef8d   2 years ago          1.05GB
seataio/seata-server   1.4.2              4909c4c024dc   2 years ago          156MB
training/webapp        latest             6fae60ef3446   8 years ago          349MB

4.使用curl验证私服库Registry上有什么镜像的指令

[email protected]:/home/my_registry#curl -XGET http://0.0.0.0:5000/v2/_catalog
{"repositories":[]}

5.修改为符合私服规范的Tag docker tag 镜像ID或镜像名:Tag Host:Port/Repository:Tag

[email protected]:/home/my_registry#docker tag hello:v1 0.0.0.0:5000/hello:v1
[email protected]:/home/my_registry#docker images
REPOSITORY             TAG                IMAGE ID       CREATED         SIZE
0.0.0.0:5000/hello     v1                 655f86577fb2   3 minutes ago   545MB
hello                  v1                 655f86577fb2   3 minutes ago   545MB
hello                  1.0                cbe82fdf9fe1   4 minutes ago   545MB
registry               latest             909c3ff012b7   5 days ago      25.4MB
postgres               12                 0d56839ac0df   3 weeks ago     412MB
redis                  latest             7c4b517da47d   3 months ago    153MB
openzipkin/zipkin      latest             7fb470c13693   4 months ago    165MB
postgres               latest             1921dda0e2c5   5 months ago    412MB
redis                  6.2.10-alpine      a470c0525301   9 months ago    27.1MB
sonarqube              8.9.10-community   4009139ebd19   11 months ago   490MB
openjdk                8                  b273004037cc   16 months ago   526MB
seataio/seata-server   1.5.2              f6a5368b6720   17 months ago   186MB
nacos/nacos-server     2.0.3              433eb51fef8d   2 years ago     1.05GB
seataio/seata-server   1.4.2              4909c4c024dc   2 years ago     156MB
training/webapp        latest             6fae60ef3446   8 years ago     349MB

6.修改配置文件使docker支持http推送

[email protected]:/home/my_registry#docker push 0.0.0.0:5000/hello:v1
The push refers to repository [0.0.0.0:5000/hello]
Get "https://0.0.0.0:5000/v2/": http: server gave HTTP response to HTTPS client

7.修改docker 配置文件/etc/docker/daemon.json ,如果不存在就创建一个daemon.json

[email protected]:/etc/docker#vi daemon.json
内容如下:
{
 "insecure-registries":["0.0.0.0:5000"]
}

重启docker

[email protected]:/etc/docker#systemctl restart docker
[email protected]:/etc/docker#docker push 0.0.0.0:5000/hello:v1
The push refers to repository [0.0.0.0:5000/hello]
Get "http://0.0.0.0:5000/v2/": dial tcp 0.0.0.0:5000: connect: connection refused
[email protected]:/etc/docker#docker ps
CONTAINER ID   IMAGE                        COMMAND                   CREATED        STATUS              PORTS                                                                                  NAMES
be0f46c5450a   seataio/seata-server:1.4.2   "java -Djava.securit…"   4 months ago   Up About a minute   0.0.0.0:8091->8091/tcp, :::8091->8091/tcp                                              seata-server
e5e9b616802c   nacos/nacos-server:2.0.3     "bin/docker-startup.…"   5 months ago   Up About a minute   0.0.0.0:8848->8848/tcp, :::8848->8848/tcp, 0.0.0.0:9848->9848/tcp, :::9848->9848/tcp   nacos203
85c7e7acf404   redis:6.2.10-alpine          "docker-entrypoint.s…"   9 months ago   Up About a minute   0.0.0.0:56379->6379/tcp, :::56379->6379/tcp     
                                       redis6.2

8.由于重启docker,导致registry服务关闭需重新启动

[email protected]:/etc/docker#docker run -d -p 5000:5000 -v /home/my_registry/:/tmp/registry --privileged=true registry
019cde034c1bf8d2bca38d70e49fa0a9c7067d2f52a30805ad06a381f7a0ad5e
[email protected]:/etc/docker#docker ps
CONTAINER ID   IMAGE                        COMMAND                   CREATED         STATUS         PORTS                                                                                  NAMES
019cde034c1b   registry                     "/entrypoint.sh /etc…"   5 seconds ago   Up 4 seconds   0.0.0.0:5000->5000/tcp, :::5000->5000/tcp                                              focused_mestorf
be0f46c5450a   seataio/seata-server:1.4.2   "java -Djava.securit…"   4 months ago    Up 4 minutes   0.0.0.0:8091->8091/tcp, :::8091->8091/tcp                                              seata-server
e5e9b616802c   nacos/nacos-server:2.0.3     "bin/docker-startup.…"   5 months ago    Up 4 minutes   0.0.0.0:8848->8848/tcp, :::8848->8848/tcp, 0.0.0.0:9848->9848/tcp, :::9848->9848/tcp   nacos203
85c7e7acf404   redis:6.2.10-alpine          "docker-entrypoint.s…"   9 months ago    Up 4 minutes   0.0.0.0:56379->6379/tcp, :::56379->6379/tcp       

9.push镜像

[email protected]:/etc/docker#docker push 0.0.0.0:5000/hello:v1
The push refers to repository [0.0.0.0:5000/hello]
7171b91e5b6c: Pushed 
f094abf7bb26: Pushed 
178dfb3c26a7: Pushed 
6b5aaff44254: Pushed 
53a0b163e995: Pushed 
b626401ef603: Pushed 
9b55156abf26: Pushed 
293d5db30c9f: Pushed 
03127cdb479b: Pushed 
9c742cd6c7a5: Pushed 
v1: digest: sha256:f7b150b6ca807187443cb4adce80e71bb5f68f2ca983bd834af5d2351740b779 size: 2422

10.push成功 查看本地仓库

[email protected]:/etc/docker#curl -XGET http://0.0.0.0:5000/v2/_catalog
{"repositories":["hello"]}

你可能感兴趣的:(Docker,docker,笔记,java)