Reputation: 26160
I would like to set the hostname for a Docker container deployed on AWS Elastic Beanstalk manually. You can set the hostname when spinning up a container with docker run -h HOSTNAME
, but I can't figure out how (or even if) to pass custom arguments to the docker run
command.
The Dockerrun.aws.json file seems a likely candidate, but there are no documented keys that do what I want.
Does anyone know if this is possible?
Upvotes: 9
Views: 2346
Reputation: 14903
Not sure about single docker container deployment i.e v1 since i haven't tried that yet but they are definitely supported in v2 i.e multi container deployment. You can adda container hostname by putting below in Dockerrun.aws.json
-
"hostname": "this-is-my-container-hostname"
Upvotes: 1
Reputation: 328
If you have multiple instance we patched old platforms with next script, but you can port it to new platforms. Example of .ebextensions/01-docker-hostname.config
:
files:
"/opt/elasticbeanstalk/hooks/appdeploy/pre/04a_set_hostname.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
hostname $(hostname -f | cut -d"." -f1,2)
sed -i "s/docker run -d \\\/docker run -d -h $(hostname) \\\/" /opt/elasticbeanstalk/hooks/appdeploy/enact/04run.sh
As you see our script always patches the run script. EB run scripts in filename order. So you should be sure that your script runs before run script.
Upvotes: 0
Reputation: 39
You can set the hostname of the container by defining it as environment variable.
HOSTNAME=your-name
Upvotes: -1
Reputation: 7997
As far as I know this is not supported out of the box.
A possible hack here is to exploit EB's poor parsing of environment variables. You can setup an environment variable such as:
PARAM1=dummy -h MYHOSTNAME
EB doesn't quote the parameters, so your -h
part will be embedded into the docker run command.
I didn't try it myself.
Another option would be to create an ebextension
file to patch the /opt/elasticbeanstalk/hooks/appdeploy/pre/04run.sh
script, injecting the -h MYHOST
line into it.
Upvotes: 3