From ed821b94ff30968f99e7d27829bdfd65ecbcbe6e Mon Sep 17 00:00:00 2001 From: qiaofeng1227 <76487013@qq.com> Date: Wed, 2 Aug 2023 17:28:43 +0800 Subject: [PATCH] use internal container ip --- appmanage/Dockerfile | 2 +- appmanage/config/cmd.sh | 3 ++- appmanage/hostname.py | 2 -- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/appmanage/Dockerfile b/appmanage/Dockerfile index db79d8a6..6e970b63 100644 --- a/appmanage/Dockerfile +++ b/appmanage/Dockerfile @@ -11,7 +11,7 @@ COPY static ./static COPY requirements.txt main.py hostname.py database.sqlite ./ RUN apt update -# Install supervisords +# Install supervisord RUN apt install -y supervisor iproute2 COPY config/supervisord.conf /etc/supervisor/conf.d/supervisord.conf COPY config/cmd.sh /cmd.sh diff --git a/appmanage/config/cmd.sh b/appmanage/config/cmd.sh index 84b4ef35..aed3474c 100644 --- a/appmanage/config/cmd.sh +++ b/appmanage/config/cmd.sh @@ -2,7 +2,8 @@ # start by supervisord internal_ip=$(ip addr show eth0 | awk '/inet /{split($2, a, "/"); print a[1]}') -python3 /usr/src/app/hostname.py +nsenter -m -u -i -n -p -t 1 sh -c "sed -i '/websoft9-appmanage/d' /etc/hosts" +nsenter -m -u -i -n -p -t 1 sh -c "echo $internal_ip websoft9-appmanage>> /etc/hosts" /usr/bin/supervisord supervisorctl start all tail -f /dev/null diff --git a/appmanage/hostname.py b/appmanage/hostname.py index e9d7ad27..7fff95e2 100644 --- a/appmanage/hostname.py +++ b/appmanage/hostname.py @@ -1,7 +1,5 @@ from api.utils.common_log import myLogger from api.utils import shell_execute -shell_execute.execute_command_output_all("echo 11111 >> /tmp/test") -shell_execute.execute_command_output_all("docker inspect websoft9-appmanage >> /tmp/test") shell_execute.execute_command_output_all("sed -i '/websoft9-appmanage/d' /etc/hosts") shell_execute.execute_command_output_all("echo $(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' websoft9-appmanage) websoft9-appmanage >> /etc/hosts") \ No newline at end of file