简体   繁体   English

将文件从Docker容器写入到AWS上的主机实例

[英]writing file from docker container to host instance on AWS

So I am using Travis CI to automatically deploy my application to AWS Elasticbeanstalk environment. 因此,我正在使用Travis CI将应用程序自动部署到AWS Elasticbeanstalk环境。 I have this issue that I need to update the nginx.conf file that is located in the host machine files. 我有这个问题,我需要更新主机文件中的nginx.conf文件。 Im running a Single container Docker image inside that host machine. 我在该主机内运行单个容器Docker映像。 How can I copy or link the nginx.conf file from docker container to host machines nginx.conf file. 如何将nginx.conf文件从docker容器复制或链接到主机nginx.conf文件。 Currently my Dockerrun.aws.json looks like that: 目前,我的Dockerrun.aws.json如下所示:

{
    "AWSEBDockerrunVersion": "1",
    "Image": {
        "Name": "some:image:url:here",
        "Update": "true"
    },
    "Ports": [
        {
            "ContainerPort": "8001"
        }
    ],
    "Volumes": [
      {
        "HostDirectory": "/etc/nginx/nginx.conf",
        "ContainerDirectory": "/home/node/app/nginx.conf"
      }
    ]
}

When I tried to use dockerrunversion: 2, it gave me an error on the build that version is wrong. 当我尝试使用dockerrunversion:2时,它在版本上给我一个错误,表明版本错误。 How can I link those two files with Single Container Docker application? 如何将这两个文件与Single Container Docker应用程序链接?

The "Volumes" key is used to map full volumes, not individual files. “卷”键用于映射完整卷,而不是单个文件。 See Dockerrun.aws.json file specifications for an explanation . 请参阅Dockerrun.aws.json 文件规范以获取解释

I know of 2 ways you can solve this problem: 1) Custom AMI or 2) use a Dockerfile with your Dockerrun.aws.json. 我知道有两种方法可以解决此问题:1)自定义AMI或2)在Dockerrun.aws.json中使用Dockerfile。

1. Build a Custom AMI 1.建立自定义AMI

The idea behind building a custom AMI is to launch an instance from one of Amazons existing AMIs. 构建自定义AMI的想法是从Amazon现有的AMI之一启动实例。 You make the changes you need to it (in your case, change the nginx.conf). 您需要对其进行更改(在您的情况下,请更改nginx.conf)。 Finally you create a new AMI from this instance and it will be available to you when you create your environment in Elastic Beanstalk. 最后,您从该实例创建一个新的AMI,当您在Elastic Beanstalk中创建环境时,该AMI将可供您使用。 Here are the detailed steps to create your own AMI and how to use it with Elastic Beanstalk . 以下是创建您自己的AMI的详细步骤以及如何将其与Elastic Beanstalk一起使用

2. Use a Dockerfile with your Dockerrun.aws.json 2.在您的Dockerrun.aws.json中使用Dockerfile

If you dont build your own AMI, you can copy your conf file with the help of a Dockerfile . 如果您不构建自己的AMI,则可以在Dockerfile的帮助下复制conf文件。 Dockerfile is a text file that provides commands to Elastic Beanstalk to run to build your custom image. Dockerfile是一个文本文件,可向Elastic Beanstalk提供命令以运行以构建您的自定义映像。 The Docerfile reference details the commands that can be added to a Dockerfile to build your image. Docerfile参考详细介绍了可以添加到Dockerfile中以构建映像的命令。 You are going to need to to use the Copy command or if the file is simple, you can use Run and echo to build it like in the example here . 你将需要使用复制命令,或者如果该文件是简单的,你可以使用Runecho建立它像例子在这里

Once you create your Dockerfile, you will need to put the Dockerfile and your Dockerrun.aws.json into a directory and create a zip file with both. 创建Dockerfile之后,您需要将Dockerfile和Dockerrun.aws.json放入目录中,并同时创建一个zip文件。 Provide this to Elastic Beanstalk as your source bundle. 将此作为源捆绑包提供给Elastic Beanstalk。 Follow this guide to build the source bundle correctly. 请按照本指南正确构建源包。

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

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