一、DockerHub发布

官网:https://hub.docker.com/

  1. [root@localhost tmp]# docker login --help
  2. Usage: docker login [OPTIONS] [SERVER]
  3. Log in to a Docker registry.
  4. If no server is specified, the default is defined by the daemon.
  5. Options:
  6. -p, --password string Password
  7. --password-stdin Take the password from stdin
  8. -u, --username string Username
  9. #登陆成功以后
  10. [root@localhost tmp]# docker push cao/centos:1.0
  11. 出现报错解决办法:
  12. The push refers to repository [docker.io/cao/centos]
  13. An image does not exist locally with the tag: cao/centos
  14. 重打标签:
  15. [root@localhost tmp]# docker images
  16. REPOSITORY TAG IMAGE ID CREATED SIZE
  17. <none> <none> 9f321222e8c9 46 minutes ago 584MB
  18. centos latest 300e315adb2f 7 months ago 209MB
  19. [root@localhost tmp]# docker tag 300e315adb2f cao/centos:1.0
  20. [root@localhost tmp]# docker images
  21. REPOSITORY TAG IMAGE ID CREATED SIZE
  22. <none> <none> 9f321222e8c9 51 minutes ago 584MB
  23. cao/centos 1.0 300e315adb2f 7 months ago 209MB
  24. centos latest 300e315adb2f 7 months ago 209MB

二、阿里云发布

官网:https://cr.console.aliyun.com/cn-hangzhou/instance/repositories

1、创建命名空间

2、创建容器镜像仓库==》仓库选本地

3、使用

image.png

三、本地打包本地导入

1、打包:

  1. docker commit -p dc8c5254acc3 nginx:v1
  2. docker ps
  3. docker save nginx:v1 > nginx.tar

2、另一台加载使用:

  1. 将两个文件夹都放到Linux /home/目录下
  2. docker load -i nginx.tar
  3. docker ps
  4. docker run -itd --name nginx nginx:v1

注意:selenux要关闭、防火墙要关闭

四、局域网仓库registry

1、拉取运行本地仓库镜像

  1. docker pull registry:2
  2. docker run -d -v /home/docker_registry:/var/lib/registry -p 5000:5000 --name myregistry registry:2
  3. 访问地址:http://127.0.0.1:5000/v2/

2、仓库服务器打包上传镜像

  1. docker commit -a "cao" -m "敏感人员" -p dc8c5254acc3 nginx:1.0
  2. docker commit -a "cao" -m "敏感人员" -p 3de6451a156a java:1.0
  3. docker commit -a "cao" -m "敏感人员" -p 256c979fcfcf redis:1.0
  4. docker commit -a "cao" -m "敏感人员" -p 05ef03502e7a mysql:1.0
  5. docker tag mysql:1.0 localhost:5000/mysql:1.0
  6. docker push localhost:5000/mysql:1.0

3、局域网服务器拉取镜像并使用

  1. 路径:/etc/docker/daemon.json
  2. 修改内网的docker默认daemon
  3. {
  4. "registry-mirrors":
  5. [
  6. "http://192.168.0.253:5000"
  7. ],
  8. "insecure-registries": ["192.168.0.253:5000"]
  9. }
  10. 拉取镜像:
  11. docker pull 192.168.0.253:5000/nginx:1.0
  12. docker pull 192.168.0.253:5000/java:1.0
  13. docker pull 192.168.0.253:5000/redis:1.0
  14. docker pull 192.168.0.253:5000/mysql:1.0
  15. 运行镜像:
  16. docker run -p 3306:3306 --name mysql --privileged=true --restart unless-stopped -v /home/docker-project/mysql/mysql:/etc/mysql -v /home/docker-project/mysql/logs:/logs -v /home/docker-project/mysql/data:/var/lib/mysql -v /etc/localtime:/etc/localtime -e MYSQL_ROOT_PASSWORD=root -d mysql:1.0