Reputation: 1
Trying to change the hostname of container with export HOSTNAME=somehost
from entrypoint.sh script but its not chaging
Attaching my current dockerfile and entrypoint.sh files Dockerfile:
FROM ubuntu:latest
RUN apt-get update && apt-get -y upgrade && DEBIAN_FRONTEND=noninteractive apt-get -y install \
apache2 \
dos2unix
WORKDIR /etc/
RUN mkdir Docker2
COPY entrypoint.sh /etc/Docker2/
WORKDIR /etc/Docker2
RUN chmod +x entrypoint.sh
RUN dos2unix entrypoint.sh
EXPOSE 80
ENTRYPOINT ["/etc/Docker2/entrypoint.sh"]
entrypoint.sh:
#!/bin/sh
set -e
export HOSTNAME=somehost
exec "$@"
cd /usr/sbin && ./apache2ctl -D FOREGROUND
Upvotes: 0
Views: 1764
Reputation: 769
edit /etc/hostname file inside the container from entrypoint.sh on startup.
echo some.host.name > /etc/hostname
Otherwise, you have to run the container with -h or --hostname option.
Upvotes: 0
Reputation: 1525
I think env HOSTNAME
only works in shell situation. Docker has provided another way to custom hostname:
docker run --hostname <name> image:tag
Upvotes: 1