Run 'docker volume create' with Ansible?How is Docker different from a virtual machine?Should I use Vagrant or Docker for creating an isolated environment?How to list containers in DockerHow to get a Docker container's IP address from the host?How to remove old Docker containersCopying files from Docker container to hostCopying files from host to Docker containerHow to test Ansible playbook using DockerUse Ansible to start Docker containers on docker-machine?How to persist data in a dockerized postgres database using volumes

Why do we need explainable AI?

How can I oppose my advisor granting gift authorship to a collaborator?

Time to call the bluff

Deleting millions of records on SQL Server 14.0

Does secure hashing imply secure symmetric encryption?

How do I name the individual parts of the lumbricals muscle of the foot in latin?

Why don't they build airplanes from 3D printer plastic?

co-son-in-law or co-brother

pruning subdomains of other domains in a file using script (bash, awk or similar)

What is the most likely cause of short, quick, and useless reviews?

std::tuple sizeof, is it a missed optimization?

To which airspace does the border of two adjacent airspaces belong to?

Global variables and information security

What is the difference between "wie" and "nach" in "Klingt wie/nach..."

How can I let authenticated users rebuild caches?

Difficult puzzle at the end of IQ test

Archiving processor does not archive

How do you manage to study and have a balance in your life at the same time?

Does POSIX guarantee the paths to any standard utilities?

Importance of electrolytic capacitor size

Does this bike use hydraulic brakes?

Adding transparency to ink drawing

Count rook moves 1D

Question about derivation of kinematics equations



Run 'docker volume create' with Ansible?


How is Docker different from a virtual machine?Should I use Vagrant or Docker for creating an isolated environment?How to list containers in DockerHow to get a Docker container's IP address from the host?How to remove old Docker containersCopying files from Docker container to hostCopying files from host to Docker containerHow to test Ansible playbook using DockerUse Ansible to start Docker containers on docker-machine?How to persist data in a dockerized postgres database using volumes






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








6















I have a Rails app I am deploying in Docker containers via Ansible. My app includes three containers so far:



  • A Docker volume container (created with docker volume create --name dbdata)

  • A Postgres container (with volumes_from dbdata)

  • The Rails app container (which links to the postgres container)

My deploy playbook is working, but I had to run the docker volume create command on the server via SSH. I'd love to do that via Ansible, so I could deploy a fresh instance of the app onto an empty container.



Is there a way to run docker volume create via Ansible, or is there some other way to do it? I checked the docs for the Ansible Docker module but it doesn't look like they support volume create yet. Unless I'm missing something?










share|improve this question
























  • Ansible can run arbitrary commands using the command or shell modules, so anything you can run on the command line you can probably run via ansible.

    – larsks
    Jan 27 '16 at 21:13











  • Yes, I thought of that, but didn't know how to do state=present like the Docker module does for containers. Though if you run docker volume create twice with the same name, the second one won't do anything because the volume will already exist. Hmmm!

    – David Ham
    Jan 27 '16 at 21:28

















6















I have a Rails app I am deploying in Docker containers via Ansible. My app includes three containers so far:



  • A Docker volume container (created with docker volume create --name dbdata)

  • A Postgres container (with volumes_from dbdata)

  • The Rails app container (which links to the postgres container)

My deploy playbook is working, but I had to run the docker volume create command on the server via SSH. I'd love to do that via Ansible, so I could deploy a fresh instance of the app onto an empty container.



Is there a way to run docker volume create via Ansible, or is there some other way to do it? I checked the docs for the Ansible Docker module but it doesn't look like they support volume create yet. Unless I'm missing something?










share|improve this question
























  • Ansible can run arbitrary commands using the command or shell modules, so anything you can run on the command line you can probably run via ansible.

    – larsks
    Jan 27 '16 at 21:13











  • Yes, I thought of that, but didn't know how to do state=present like the Docker module does for containers. Though if you run docker volume create twice with the same name, the second one won't do anything because the volume will already exist. Hmmm!

    – David Ham
    Jan 27 '16 at 21:28













6












6








6


2






I have a Rails app I am deploying in Docker containers via Ansible. My app includes three containers so far:



  • A Docker volume container (created with docker volume create --name dbdata)

  • A Postgres container (with volumes_from dbdata)

  • The Rails app container (which links to the postgres container)

My deploy playbook is working, but I had to run the docker volume create command on the server via SSH. I'd love to do that via Ansible, so I could deploy a fresh instance of the app onto an empty container.



Is there a way to run docker volume create via Ansible, or is there some other way to do it? I checked the docs for the Ansible Docker module but it doesn't look like they support volume create yet. Unless I'm missing something?










share|improve this question














I have a Rails app I am deploying in Docker containers via Ansible. My app includes three containers so far:



  • A Docker volume container (created with docker volume create --name dbdata)

  • A Postgres container (with volumes_from dbdata)

  • The Rails app container (which links to the postgres container)

My deploy playbook is working, but I had to run the docker volume create command on the server via SSH. I'd love to do that via Ansible, so I could deploy a fresh instance of the app onto an empty container.



Is there a way to run docker volume create via Ansible, or is there some other way to do it? I checked the docs for the Ansible Docker module but it doesn't look like they support volume create yet. Unless I'm missing something?







docker ansible






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 27 '16 at 20:56









David HamDavid Ham

3914 silver badges21 bronze badges




3914 silver badges21 bronze badges















  • Ansible can run arbitrary commands using the command or shell modules, so anything you can run on the command line you can probably run via ansible.

    – larsks
    Jan 27 '16 at 21:13











  • Yes, I thought of that, but didn't know how to do state=present like the Docker module does for containers. Though if you run docker volume create twice with the same name, the second one won't do anything because the volume will already exist. Hmmm!

    – David Ham
    Jan 27 '16 at 21:28

















  • Ansible can run arbitrary commands using the command or shell modules, so anything you can run on the command line you can probably run via ansible.

    – larsks
    Jan 27 '16 at 21:13











  • Yes, I thought of that, but didn't know how to do state=present like the Docker module does for containers. Though if you run docker volume create twice with the same name, the second one won't do anything because the volume will already exist. Hmmm!

    – David Ham
    Jan 27 '16 at 21:28
















Ansible can run arbitrary commands using the command or shell modules, so anything you can run on the command line you can probably run via ansible.

– larsks
Jan 27 '16 at 21:13





Ansible can run arbitrary commands using the command or shell modules, so anything you can run on the command line you can probably run via ansible.

– larsks
Jan 27 '16 at 21:13













Yes, I thought of that, but didn't know how to do state=present like the Docker module does for containers. Though if you run docker volume create twice with the same name, the second one won't do anything because the volume will already exist. Hmmm!

– David Ham
Jan 27 '16 at 21:28





Yes, I thought of that, but didn't know how to do state=present like the Docker module does for containers. Though if you run docker volume create twice with the same name, the second one won't do anything because the volume will already exist. Hmmm!

– David Ham
Jan 27 '16 at 21:28












3 Answers
3






active

oldest

votes


















10
















Here's one option, using the command module.



- hosts: localhost
tasks:
- name: check if myvolume exists
command: docker volume inspect myvolume
register: myvolume_exists
failed_when: false

- name: create myvolume
command: docker volume create --name myvolume
when: myvolume_exists|failed


We first check if the volume exists by using docker volume inspect. We save the result of that task in the variable myvolume_exists, and then we only create the volume if the inspect task failed.






share|improve this answer

























  • This should work great. Thank you!

    – David Ham
    Jan 28 '16 at 16:34


















3
















You can now use -v argument to create named volumes, from man page of docker run:




If you supply a name, Docker creates a named volume by that name.




 - name: Run mariadb
docker_container:
name: mariadb-container
image: mariadb
env:
MYSQL_ROOT_PASSWORD: "secret-password"
MYSQL_DATABASE: "db"
MYSQL_USER: "user"
MYSQL_PASSWORD: "password"
ports:
- "3306:3306"
volumes:
- mariadb-data:/var/lib/mysql


mariadb-data is a named volume which was automatically created by docker:



$ docker volume inspect mariadb-data
[

"Name": "mariadb-data",
"Driver": "local",
"Mountpoint": "/var/lib/docker/volumes/mariadb-data/_data",
"Labels": null,
"Scope": "local"

]





share|improve this answer
































    0
















    You can manage docker volumes with Ansible's own docker_volume module. New in version 2.4.






    share|improve this answer



























      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f35047813%2frun-docker-volume-create-with-ansible%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      10
















      Here's one option, using the command module.



      - hosts: localhost
      tasks:
      - name: check if myvolume exists
      command: docker volume inspect myvolume
      register: myvolume_exists
      failed_when: false

      - name: create myvolume
      command: docker volume create --name myvolume
      when: myvolume_exists|failed


      We first check if the volume exists by using docker volume inspect. We save the result of that task in the variable myvolume_exists, and then we only create the volume if the inspect task failed.






      share|improve this answer

























      • This should work great. Thank you!

        – David Ham
        Jan 28 '16 at 16:34















      10
















      Here's one option, using the command module.



      - hosts: localhost
      tasks:
      - name: check if myvolume exists
      command: docker volume inspect myvolume
      register: myvolume_exists
      failed_when: false

      - name: create myvolume
      command: docker volume create --name myvolume
      when: myvolume_exists|failed


      We first check if the volume exists by using docker volume inspect. We save the result of that task in the variable myvolume_exists, and then we only create the volume if the inspect task failed.






      share|improve this answer

























      • This should work great. Thank you!

        – David Ham
        Jan 28 '16 at 16:34













      10














      10










      10









      Here's one option, using the command module.



      - hosts: localhost
      tasks:
      - name: check if myvolume exists
      command: docker volume inspect myvolume
      register: myvolume_exists
      failed_when: false

      - name: create myvolume
      command: docker volume create --name myvolume
      when: myvolume_exists|failed


      We first check if the volume exists by using docker volume inspect. We save the result of that task in the variable myvolume_exists, and then we only create the volume if the inspect task failed.






      share|improve this answer













      Here's one option, using the command module.



      - hosts: localhost
      tasks:
      - name: check if myvolume exists
      command: docker volume inspect myvolume
      register: myvolume_exists
      failed_when: false

      - name: create myvolume
      command: docker volume create --name myvolume
      when: myvolume_exists|failed


      We first check if the volume exists by using docker volume inspect. We save the result of that task in the variable myvolume_exists, and then we only create the volume if the inspect task failed.







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Jan 27 '16 at 21:33









      larskslarsks

      135k23 gold badges223 silver badges222 bronze badges




      135k23 gold badges223 silver badges222 bronze badges















      • This should work great. Thank you!

        – David Ham
        Jan 28 '16 at 16:34

















      • This should work great. Thank you!

        – David Ham
        Jan 28 '16 at 16:34
















      This should work great. Thank you!

      – David Ham
      Jan 28 '16 at 16:34





      This should work great. Thank you!

      – David Ham
      Jan 28 '16 at 16:34













      3
















      You can now use -v argument to create named volumes, from man page of docker run:




      If you supply a name, Docker creates a named volume by that name.




       - name: Run mariadb
      docker_container:
      name: mariadb-container
      image: mariadb
      env:
      MYSQL_ROOT_PASSWORD: "secret-password"
      MYSQL_DATABASE: "db"
      MYSQL_USER: "user"
      MYSQL_PASSWORD: "password"
      ports:
      - "3306:3306"
      volumes:
      - mariadb-data:/var/lib/mysql


      mariadb-data is a named volume which was automatically created by docker:



      $ docker volume inspect mariadb-data
      [

      "Name": "mariadb-data",
      "Driver": "local",
      "Mountpoint": "/var/lib/docker/volumes/mariadb-data/_data",
      "Labels": null,
      "Scope": "local"

      ]





      share|improve this answer





























        3
















        You can now use -v argument to create named volumes, from man page of docker run:




        If you supply a name, Docker creates a named volume by that name.




         - name: Run mariadb
        docker_container:
        name: mariadb-container
        image: mariadb
        env:
        MYSQL_ROOT_PASSWORD: "secret-password"
        MYSQL_DATABASE: "db"
        MYSQL_USER: "user"
        MYSQL_PASSWORD: "password"
        ports:
        - "3306:3306"
        volumes:
        - mariadb-data:/var/lib/mysql


        mariadb-data is a named volume which was automatically created by docker:



        $ docker volume inspect mariadb-data
        [

        "Name": "mariadb-data",
        "Driver": "local",
        "Mountpoint": "/var/lib/docker/volumes/mariadb-data/_data",
        "Labels": null,
        "Scope": "local"

        ]





        share|improve this answer



























          3














          3










          3









          You can now use -v argument to create named volumes, from man page of docker run:




          If you supply a name, Docker creates a named volume by that name.




           - name: Run mariadb
          docker_container:
          name: mariadb-container
          image: mariadb
          env:
          MYSQL_ROOT_PASSWORD: "secret-password"
          MYSQL_DATABASE: "db"
          MYSQL_USER: "user"
          MYSQL_PASSWORD: "password"
          ports:
          - "3306:3306"
          volumes:
          - mariadb-data:/var/lib/mysql


          mariadb-data is a named volume which was automatically created by docker:



          $ docker volume inspect mariadb-data
          [

          "Name": "mariadb-data",
          "Driver": "local",
          "Mountpoint": "/var/lib/docker/volumes/mariadb-data/_data",
          "Labels": null,
          "Scope": "local"

          ]





          share|improve this answer













          You can now use -v argument to create named volumes, from man page of docker run:




          If you supply a name, Docker creates a named volume by that name.




           - name: Run mariadb
          docker_container:
          name: mariadb-container
          image: mariadb
          env:
          MYSQL_ROOT_PASSWORD: "secret-password"
          MYSQL_DATABASE: "db"
          MYSQL_USER: "user"
          MYSQL_PASSWORD: "password"
          ports:
          - "3306:3306"
          volumes:
          - mariadb-data:/var/lib/mysql


          mariadb-data is a named volume which was automatically created by docker:



          $ docker volume inspect mariadb-data
          [

          "Name": "mariadb-data",
          "Driver": "local",
          "Mountpoint": "/var/lib/docker/volumes/mariadb-data/_data",
          "Labels": null,
          "Scope": "local"

          ]






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 23 '17 at 13:32









          SummerBreezeSummerBreeze

          3,8652 gold badges19 silver badges20 bronze badges




          3,8652 gold badges19 silver badges20 bronze badges
























              0
















              You can manage docker volumes with Ansible's own docker_volume module. New in version 2.4.






              share|improve this answer





























                0
















                You can manage docker volumes with Ansible's own docker_volume module. New in version 2.4.






                share|improve this answer



























                  0














                  0










                  0









                  You can manage docker volumes with Ansible's own docker_volume module. New in version 2.4.






                  share|improve this answer













                  You can manage docker volumes with Ansible's own docker_volume module. New in version 2.4.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 28 at 2:40









                  Link SwansonLink Swanson

                  1315 bronze badges




                  1315 bronze badges






























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f35047813%2frun-docker-volume-create-with-ansible%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                      SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                      은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현