I think you're trying to solve an incorrect problem: you're supposed to deploy a Docker image that is already configured the way you need it. It would be best if you did not make any configuration changes during deployment. Doing so will tightly couple your Docker image behaviour to your deployment process, exposing you to a risk of having different behaviour between individual environments (local dev Docker vs. production EB Docker, fox example). Eliminating this risk is one of the reasons Docker exists in the first place.
To answer your question of "how to use .ebextensions
in Docker platform:"
Long story short, assuming you have a pre-built Docker image, just create a zip file containing your docker-compose.yml
and .ebextensions
and use the zip file to deploy a new version.
You can find a complete answer in https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/single-container-docker-configuration.html#docker-configuration.remote-repo if you expand the "Using the AWS Systems Manager (SSM) Parameter Store" section.
Just in case the AWS website changed, here is the directory structure they propose:
├── .ebextensions
│ └── env.config
├── .platform
│ ├── confighooks
│ │ └── pre-build
│ │ └── 01login.sh
│ └── hooks
│ └── pre-build
│ └── 01login.sh
├── docker-compose.yml
In this example, they are using .ebextensions
to configure environment variables later used to log in to Docker Hub.
In your case, you can use a file in .ebextensions
to either run commands or replace configuration files altogether. Check out Github repo with samples; it's an excellent source of inspiration. One of the examples in particular demonstrates how to update the Nginx configuration.
Alternatively, you can run any commands in your .platform/hooks
directory.
The commands you want to run to tweak your Nginx configuration are, of course, docker exec ...
, but I repeat, if you plan to tweak Nginx-in-Docker configuration on deploy, you're probably doing it wrong.
If you run your docker exec ...
commands, you need to ensure you're running them on the correct containers. I can't give you further guidance in that regard as I have never done it this way, and, I repeat, I don't think you should do it this way.
Do share the solution if you find one.