简体   繁体   English

尝试在 AWS 上启动时 docker-compose 返回错误

[英]docker-compose returns error when trying to start on AWS

I want to deploy my server to an AWS EC2 instance.我想将我的服务器部署到 AWS EC2 实例。 When I enter 'sudo docker-compose up' in the ssh console, I get the following error:当我在 ssh 控制台中输入“sudo docker-compose up”时,出现以下错误:

ERROR: for nginx Cannot start service nginx: OCI runtime create failed: container_linux.go:345: starting container process caused "process_linux.go:430: container init caused \"rootfs_linux.go:58: mounting \\"/home/ubuntu/site/nginx/default.conf\\" to rootfs \\"/var/lib/docker/overlay2/b24f64910c6ab7727a4cb08afac0d034bb759baa4bfd605466ca760359f411c2/merged\\" at \\"/var/lib/docker/overlay2/b24f64910c6ab7727a4cb08afac0d034bb759baa4bfd605466ca760359f411c2/merged/etc/nginx/conf.d/default.conf\\" caused \\"not a directory\\"\"": unknown: Are you trying to mount a directory onto a file (or vice-versa)? ERROR: for nginx Cannot start service nginx: OCI runtime create failed: container_linux.go:345: starting container process caused "process_linux.go:430: container init caused \"rootfs_linux.go:58: mounting \\"/home/ubuntu /site/nginx/default.conf\\" to rootfs \\"/var/lib/docker/overlay2/b24f64910c6ab7727a4cb08afac0d034bb759baa4bfd605466ca760359f411c2/merged\\" at \\"/var/lib/docker/overlay2/b24f64910c6ab7727a4cb08afac0d034bb759baa4bfd605466ca760359f411c2/merged/etc/ nginx/conf.d/default.conf\\" 导致 \\"not a directory\\"\\"": 未知:您是否尝试将目录挂载到文件上(反之亦然)? Check if the specified host path exists and is the expected type检查指定的主机路径是否存在并且是预期的类型

This is my docker-compose.yml file:这是我的 docker-compose.yml 文件:

version: '2'

networks:
    SRVR:

services:
    nginx:
        image: nginx:stable-alpine
        container_name: SRVR_nginx
        ports:
            - "8080:80"
        volumes:
            - ./code:/code
            - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
            - ./nginx/logs:/var/log/nginx
        depends_on:
            - php
        networks:
            - SRVR

    php:
        build: ./php
        container_name: SRVR_php
        volumes:
            - ./code:/code
        ports:
            - "9000:9000"
        networks:
            - SRVR

The same docker-compose.yml is working fine on my local compuer which runs Ubuntu OS.相同的 docker-compose.yml 在我运行 Ubuntu 操作系统的本地计算机上运行良好。 The EC2 instance also runs Ubuntu OS. EC2 实例还运行 Ubuntu 操作系统。

Your problem is with ./nginx/default.conf .你的问题是./nginx/default.conf docker recognises that as a folder and you have /etc/nginx/conf.d/default.conf being a file. docker 将其识别为文件夹,并且您将/etc/nginx/conf.d/default.conf作为文件。

I was too hasty to ask.我太仓促了,不敢问。 Here's what's going on.这是正在发生的事情。 The Nginx container requires the 'default.conf' file to be created manually. Nginx 容器需要手动创建“default.conf”文件。 If it's not, bringing nginx server up creates a folder called 'default.conf'.如果不是,则启动 nginx 服务器会创建一个名为“default.conf”的文件夹。 Once I've manually copied my original 'default.conf' file to the appropriate location, everything seems to be working fine.一旦我手动将原始的“default.conf”文件复制到适当的位置,一切似乎都工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM