Ansible将容器部署到本地映像的远程位置

时间:2020-05-28 03:37:22

标签: 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\"}'\")"}

所以我的问题是

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

1 个答案:

答案 0 :(得分:1)

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

首先:在您的计算机上添加docker注册。

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

second:将您的映像推送到localhost。

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

命令只是将您的docker映像推送到计算机上的docker注册表中。 假定您的计算机ipaddress为10.10.1.12,然后在服务器端运行命令blow。

thred:拉动

docker pull 10.10.1.12:5000/ipdata:latest

如果您在不使用https的情况下使用它,也许您会遇到问题: Private registry push fail: server gave HTTP response to HTTPS client

只是流解决方案的打击,以更改服务器端的docker客户端配置。会没事的。 https://github.com/docker/distribution/issues/1874#issuecomment-237194314

相关问题