dockeransible

ansible deploy container to remote from local image


i have created images on my local instance want to deploy container from that image here is my playbook code

  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

when running this playbook it sends me this error

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

so my questions are

  1. is it possible to
  2. or do i need to copy all file on remote then create image and then create container from that image
  3. that will be great if some one share a sample code which will create image and then deploy containers .

Solution

  • you need a docker registry, just do this:

    first: add a docker register on your machine.

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

    second: push your image to localhost.

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

    command upon the localhost is just push your docker image into docker registry on your machine. assume your machine ipaddress is 10.10.1.12, then run command blow on your server side.

    thrid: pull it

    docker pull 10.10.1.12:5000/ipdata:latest
    

    if you are using it without https, maybey you will meet issue blow: Private registry push fail: server gave HTTP response to HTTPS client

    just flow solution blow to change your docker client config on your server side. it will be ok. https://github.com/docker/distribution/issues/1874#issuecomment-237194314