zoukankan      html  css  js  c++  java
  • 发布Docker 镜像到dockerhub

    公有仓库

    docker提供了一个类似于github的仓库dockerhub, 网址 https://hub.docker.com/ 需要注册使用

    注意要保证image的tag是账户名,如果镜像名字不对,需要改一下tag

            docker  tag   wl/centos-vim   wanglan/centos-vim

    语法是: docker   tag    仓库名                wanglan/仓库名

    注册docker id后,在linux中登录dockerhub

    [root@localhost mydocker]# docker login
    Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
    Username: 

    上传镜像(上传hello-world)

    [root@localhost mydocker]# docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    ubuntu              latest              94e814e2efa8        2 days ago          88.9MB
    hello-world         latest              fce289e99eb9        2 months ago        1.84kB
    centos              latest              1e1148e4cc2c        3 months ago        202MB
    
    [root@localhost mydocker]# docker tag fce wanglan/hello-world
    
    [root@localhost mydocker]# docker images
    REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
    ubuntu                latest              94e814e2efa8        2 days ago          88.9MB
    hello-world           latest              fce289e99eb9        2 months ago        1.84kB
    wanglan/hello-world   latest              fce289e99eb9        2 months ago        1.84kB
    centos                latest              1e1148e4cc2c        3 months ago        202MB
    
    [root@localhost mydocker]# docker push wanglan/hello-world
    The push refers to repository [docker.io/wanglan/hello-world]
    af0b15c8625b: Mounted from library/hello-world 
    latest: digest: sha256:92c7f9c92844bbbb5d0a101b22f7c2a7949e40f8ea90c8b3bc396879d95e899a size: 524

    查看

    私有仓库

    但是这种镜像仓库是公开的,其他人也是可以下载,并不安全,因此还可以使用docker registry官方提供的私有仓库

    官方提供的私有仓库docker registry用法

    https://yeasy.gitbooks.io/docker_practice/repository/registry.html

    一条命令下载registry镜像并且启动私有仓库容器

    私有仓库会被创建在容器的/var/lib/registry下,因此通过-v参数将镜像文件存储到本地的/opt/data/registry下,端口映射容器中的5000端口到宿主机的5000端口
    
    [root@localhost mydocker]# docker run -d 
          -p 5000:5000 
          -v /opt/data/registry:/var/lib/registry 
          registry

    检查启动registry容器

    [root@localhost mydocker]# docker ps

    测试连接容器

    [root@localhost mydocker]# telnet 192.168.11.174 5000
    Trying 192.168.11.174...
    Connected to 192.168.11.174.
    Escape character is '^]'.
    
    或输入ip:端口访问

    修改镜像tag,以docker registry的地址端口开头

    [root@localhost mydocker]# docker tag hello-world 192.168.11.174:5000/hello-world

    Docker 默认不允许非 HTTPS 方式推送镜像。我们可以通过 Docker 的配置选项来取消这个限制,这里必须写正确json数据

    [root@localhost opt]# cat /etc/docker/daemon.json 
    {"registry-mirrors": ["http://95822026.m.daocloud.io"],
    "insecure-registries":["192.168.11.174:5000"]
    }

    修改了docker配置文件,需要制定docker服务,去加载这些代码,编辑这个文件 /lib/systemd/system/docker.service ,写入新的配置

    vim /lib/systemd/system/docker.service
    写入如下配置,改成和我一样就行
    [Service]
    EnvironmentFile=-/etc/docker/daemon.json

    修改了docker配置文件,重新加载docker

    [root@localhost opt]# systemctl daemon-reload

    重启docker

    [root@localhost opt]# systemctl restart docker

    由于重启了docker,私有仓库的容器也挂了,需要重新启动

    docker run --privileged=true -d -p 5000:5000 -v /opt/data/registry:/var/lib/registry registry

    推送本地镜像到 私有仓库

    [root@localhost system]# docker push 192.168.11.174:5000/hello-world







  • 相关阅读:
    几种流行Webservice框架性能对比
    java实现的单点登录
    SQL Server性能调优——报表数据库与业务数据库分离
    控制台console输出信息原理理解
    查看程序是否启动或者关闭--比如查看Tomcat是否开启!直接用ps命令查看进程就行了啊
    Tomcat日志问题
    客户端用httpurlconnection来进行http连接的
    一个tomcat上放多个webapp问题,那这多个webapp会不会竞争端口呢?不会!安全两码事
    ps -ef能列出进程号,和端口号没任何关系
    Tomcat打印运行时日志(控制台),访问日志,启动日志
  • 原文地址:https://www.cnblogs.com/wanglan/p/7458255.html
Copyright © 2011-2022 走看看