docker - 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\"}'\")"}
所以我的问题是
- 是否有可能
- 还是我需要复制远程上的所有文件然后创建图像然后从该图像创建容器
- 如果有人分享一个创建图像然后部署容器的示例代码,那就太好了。
解决方案
您需要一个 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
推荐阅读
- c++ - 带有函数指针的 C++ 运算符优先级
- php - 如何传递资源查看?
- javascript - 如何理解这个 Node.js 代码片段?
- python - 使用 Python 在不同模块中导入函数的返回值时出错
- swift - Swift - 如何在加载 ViewController 之前正确实现 CoreData 的更新/设置以供使用
- powershell - Move-Item 的通配符问题
- jquery - 如何使用 div 标签和 jquery 从侧边菜单加载 html 页面
- javascript - (JavaScript) 将数组中的每个数字相加以使其永远不会低于 1 所需的最小数字
- protractor - Protractor console.log 中的空响应
- python - 在python中删除()和[]之间的文本,但有一些例外