我有以下Docker命令:
docker run -d --name ADMIN_SERVER_TEST1 --network=soa_net --ip=172.16.1.11 -p 7001:7001 -v /Oracle_Volumes/ENVIRONMENTS/TEST1/SOA-Volume/cheetah_domain:/u01/oracle/user_projects --env-file $ENV_HOME/adminserver-test1.env.list --env-file $ENV_HOME/soaserver-test1.env.list -u root redreply/soa-suite:12.2.1.3 ./dockertools/createDomainAndStart.sh && docker logs -f ADMIN_SERVER_TEST1
对于此命令,我使用Ansible创建了以下脚本:
- name: Create SOA container
docker_container:
name: "{{ name }}"
image: "{{ image }}"
detach: yes
privileged: yes
user: root
volumes:
- "{{ src_vol }}:{{ dest_vol }}"
ports:
- 7001:7001
networks:
- name: soa_net
ipv4_address: "{{ ip }}"
env_file:
- "{{ env_file_1}}"
- "{{ env_file_2}}"
但是我不知道如何将此部分添加到Ansible脚本中:
./dockertools/createDomainAndStart.sh && docker logs -f ADMIN_SERVER_TEST1
答案 0 :(得分:2)
如果要将脚本运行为command
并在容器启动时在容器中执行,则可以使用command
属性来指定该脚本,如下所示:
- name: Create SOA container
docker_container:
name: "{{ name }}"
image: "{{ image }}"
detach: yes
privileged: yes
user: root
command: ./dockertools/createDomainAndStart.sh
volumes:
- "{{ src_vol }}:{{ dest_vol }}"
ports:
- 7001:7001
networks:
- name: soa_net
ipv4_address: "{{ ip }}"
env_file:
- "{{ env_file_1}}"
- "{{ env_file_2}}"
我基本上添加了command
属性以在容器启动时调用您的./dockertools/createDomainAndStart.sh
脚本。
Ansible documentation的command
属性描述如下:
在容器启动时执行的命令。命令可以是字符串或列表。在2.4版之前,字符串以逗号分隔。