简体   繁体   中英

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. I have this issue that I need to update the nginx.conf file that is located in the host machine files. Im running a Single container Docker image inside that host machine. How can I copy or link the nginx.conf file from docker container to host machines nginx.conf file. Currently my Dockerrun.aws.json looks like that:

{
    "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. How can I link those two files with Single Container Docker application?

The "Volumes" key is used to map full volumes, not individual files. See Dockerrun.aws.json file specifications for an explanation .

I know of 2 ways you can solve this problem: 1) Custom AMI or 2) use a Dockerfile with your Dockerrun.aws.json.

1. Build a Custom AMI

The idea behind building a custom AMI is to launch an instance from one of Amazons existing AMIs. You make the changes you need to it (in your case, change the 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. Here are the detailed steps to create your own AMI and how to use it with Elastic Beanstalk .

2. Use a Dockerfile with your Dockerrun.aws.json

If you dont build your own AMI, you can copy your conf file with the help of a Dockerfile . Dockerfile is a text file that provides commands to Elastic Beanstalk to run to build your custom image. The Docerfile reference details the commands that can be added to a Dockerfile to build your image. 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 .

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. Provide this to Elastic Beanstalk as your source bundle. Follow this guide to build the source bundle correctly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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