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;
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
add a comment |
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
Ansible can run arbitrary commands using thecommand
orshell
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 dostate=present
like the Docker module does for containers. Though if you rundocker 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
add a comment |
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
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
docker ansible
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 thecommand
orshell
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 dostate=present
like the Docker module does for containers. Though if you rundocker 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
add a comment |
Ansible can run arbitrary commands using thecommand
orshell
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 dostate=present
like the Docker module does for containers. Though if you rundocker 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
add a comment |
3 Answers
3
active
oldest
votes
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.
This should work great. Thank you!
– David Ham
Jan 28 '16 at 16:34
add a comment |
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"
]
add a comment |
You can manage docker volumes with Ansible's own docker_volume module. New in version 2.4.
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
This should work great. Thank you!
– David Ham
Jan 28 '16 at 16:34
add a comment |
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.
This should work great. Thank you!
– David Ham
Jan 28 '16 at 16:34
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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"
]
add a comment |
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"
]
add a comment |
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"
]
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"
]
answered Jan 23 '17 at 13:32
SummerBreezeSummerBreeze
3,8652 gold badges19 silver badges20 bronze badges
3,8652 gold badges19 silver badges20 bronze badges
add a comment |
add a comment |
You can manage docker volumes with Ansible's own docker_volume module. New in version 2.4.
add a comment |
You can manage docker volumes with Ansible's own docker_volume module. New in version 2.4.
add a comment |
You can manage docker volumes with Ansible's own docker_volume module. New in version 2.4.
You can manage docker volumes with Ansible's own docker_volume module. New in version 2.4.
answered Mar 28 at 2:40
Link SwansonLink Swanson
1315 bronze badges
1315 bronze badges
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Ansible can run arbitrary commands using the
command
orshell
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 rundocker 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