使用可执行文件在Docker容器中运行命令 [英] Run Command Inside of Docker Container Using Ansible
问题描述
我想要完成的是在Docker容器中运行命令,该容器已经使用Ansible在数字海洋Ubuntu / Docker Droplet上创建。
what I'm trying to accomplish is to run commands inside of a Docker container that has already been created on a Digital Ocean Ubuntu/Docker Droplet using Ansible.
似乎没有找到任何东西,或者我主要缺少一些东西。这是我在我的书中的安全任务。我非常新的可以安全,所以任何建议或智慧将不胜感激。
Can't seem to find anything on this, or I'm majorly missing something. This is my Ansible task in my play book. I'm very new to Ansible so any advice or wisdom would be greatly appreciated.
- name: Test Deploy
hosts: [my-cluster-of-servers]
tasks:
- name: Go Into Docker Container And Run Multiple Commands
docker:
name: [container-name]
image: [image-ive-created-container-with-on-server]
state: present
command: docker exec -it [container-name] bash
推荐答案
你应该能够执行一个脚本在其中) docker exec
:
You should be able to execute a script (with your sequence of command in it) with docker exec
:
docker exec container-name bash -l -c /path/to/script > /path/to/log
(另请参见为什么我必须在我的容器内使用 bash -l -c
)
(See also "Why do I have to use bash -l -c
inside my container?")
-
/ path / to / script
-
/ path / to / log
是容器内的路径,可以在卷中共享。 b $ b
/path/to/script
should be accessible by your Ansible process./path/to/log
is a path inside the container, that could be shared in a volume.
这篇关于使用可执行文件在Docker容器中运行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!