使用卷时无法启动nginx容器(使用ansible和docker-compose)

时间:2020-11-11 15:51:27

标签: docker nginx docker-compose ansible

我正在尝试使用ansible和docker-compose从一台机器到另一台机器来启动nginx容器。

每当我将nginx.conf包含到卷中时,就会出现我不理解的错误。 仅创建容器,而不启动容器。

MACHINE-1

运行剧本的命令:ansible-playbook -v nginx-playbook.yml -l ubuntu_node_1 -u root

我的剧本:

- name: nginx-docker_compose
  hosts: all
  gather_facts: yes
  become: yes
  tasks:
    - community.general.docker_compose:
        project_name: nginx
        definition:
          version: '2'
          services:
            web:
              image: nginx:latest
              volumes:
                - ./vars/nginx.conf:/etc/nginx/nginx.conf:ro
              ports:
                - "8080:80"

[编辑]

这是错误:

Using /etc/ansible/ansible.cfg as config file

PLAY [nginx-docker_compose] ********************************************************************************************************************************************

TASK [Gathering Facts] *************************************************************************************************************************************************
[DEPRECATION WARNING]: Distribution Ubuntu 18.04 on host 172.31.15.176 should use /usr/bin/python3, but is using /usr/bin/python for backward compatibility with prior
Ansible releases. A future Ansible release will default to using the discovered platform python for this host. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information. This feature will be removed in version 2.12. Deprecation
warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
ok: [172.31.15.176]

TASK [community.general.docker_compose] ********************************************************************************************************************************
fatal: [172.31.15.176]: FAILED! => {"changed": false, "errors": [], "module_stderr": "Recreating nginx_web_1 ... \n\u001b[1A\u001b[2K\nRecreating nginx_web_1 ... \n\u001b[1B", "module_stdout": "", "msg": "Error starting project Encountered errors while bringing up the project."}

PLAY RECAP *************************************************************************************************************************************************************
172.31.15.176              : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

[root@ip-172-31-12-130 docker_server]# ansible-playbook -v nginx-playbook.yml -l ubuntu_node_1 -u root
Using /etc/ansible/ansible.cfg as config file

PLAY [nginx-docker_compose] ********************************************************************************************************************************************

TASK [Gathering Facts] *************************************************************************************************************************************************
[DEPRECATION WARNING]: Distribution Ubuntu 18.04 on host 172.31.15.176 should use /usr/bin/python3, but is using /usr/bin/python for backward compatibility with prior
Ansible releases. A future Ansible release will default to using the discovered platform python for this host. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information. This feature will be removed in version 2.12. Deprecation
warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
ok: [172.31.15.176]

TASK [community.general.docker_compose] ********************************************************************************************************************************
fatal: [172.31.15.176]: FAILED! => {"changed": false, "errors": [], "module_stderr": "Recreating 9b102bbf98c2_nginx_web_1 ... \n\u001b[1A\u001b[2K\nRecreating 9b102bbf98c2_nginx_web_1 ... \n\u001b[1B", "module_stdout": "", "msg": "Error starting project Encountered errors while bringing up the project."}

PLAY RECAP *************************************************************************************************************************************************************
172.31.15.176              : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

注意:当我尝试在MACHINE-2上使用相同配置直接使用docker-compose直接运行nginx容器时,它可以工作。 我相信在尝试从MACHINE-1到MACHINE-2执行剧本时会发生一些权限问题,但无法弄清楚。

1 个答案:

答案 0 :(得分:0)

现在可以使用。感谢@mdaniel。

我更改的内容:

  1. 我将整个目录写在了剧本中-/home/some_more_folders/nginx.conf

  2. ,并在目标计算机上复制了具有相同目录结构的相同文件。

仍然有待解决的问题:

  1. 您知道为什么有必要将任何文件复制到目标计算机(例如nginx.conf)吗?

  2. 如何手动执行将配置文件复制到docker-compose的目标计算机的手动过程?

相关问题