首页 > 解决方案 > ansible 将容器部署到远程本地映像

问题描述

我已经在我的本地实例上创建了图像想要从该图像部署容器这是我的剧本代码

  hosts: all
  remote_user: root
 become: yes
 become_method: sudo
 tasks:
 - name: Install pip
   apt: name=python3-pip state=present

 - name: Running the container
   docker_container:
     name: tmep
     image: ipdata:latest
     pull: no

 - name: Check if container is running
   shell: docker ps

运行此剧本时,它会向我发送此错误

FAILED! => {"changed": false, "msg": "Error pulling image ipdata:latest - 404 Client Error: Not Found (\"b'{\"message\":\"pull access denied for ipdata, repository does not exist or may require \\'docker login\\': denied: requested access to the resource is denied\"}'\")"}

所以我的问题是

  1. 是否有可能
  2. 还是我需要复制远程上的所有文件然后创建图像然后从该图像创建容器
  3. 如果有人分享一个创建图像然后部署容器的示例代码,那就太好了。

标签: dockeransible

解决方案


您需要一个 docker 注册表,只需执行以下操作:

首先:在你的机器上添加一个 docker register。

docker run -d -p 5000:5000 --restart always --name registry registry:2

第二:将您的图像推送到本地主机。

docker tag ipdata:latest localhost:5000/ipdata:latest 
docker push localhost:5000/ipdata:latest 

上的命令localhost只是将您的 docker 映像推送到您机器上的 docker 注册表中。假设您的机器 ipaddress 是 10.10.1.12,然后在您的服务器端运行命令打击。

第三:拉

docker pull 10.10.1.12:5000/ipdata:latest

如果您在没有 https 的情况下使用它,也许您会遇到问题: 私有注册表推送失败:服务器向 HTTPS 客户端提供 HTTP 响应

只需流动解决方案即可更改服务器端的 docker 客户端配置。会没事的。 https://github.com/docker/distribution/issues/1874#issuecomment-237194314


推荐阅读