Skip to content

Commit 1a67497

Browse files
Fix duplicate entry in file
1 parent 3ee2aa7 commit 1a67497

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

compose/bin/extra-settings

+8-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
33
# Get the IP address from the Docker container
44
docker_ip=$(docker run --rm alpine ip route | awk 'NR==1 {print $3}')
55

6-
# Add a new entry to /etc/hosts
7-
echo "$docker_ip host.docker.internal" | sudo tee -a /etc/hosts
8-
echo "A new entry in the /etc/hosts file has been created"
6+
# Check if the IP address already exists in /etc/hosts
7+
if grep -q "$docker_ip host.docker.internal" /etc/hosts; then
8+
echo "The entry already exists in /etc/hosts. No action needed."
9+
else
10+
# Add a new entry to /etc/hosts
11+
echo "$docker_ip host.docker.internal" | sudo tee -a /etc/hosts
12+
echo "A new entry in the /etc/hosts file has been created"
13+
fi
914

1015
# Ask the user whether to execute the iptables command
1116
read -p "Do you want to open port 9003 for xdebug? (y/n): " choice

0 commit comments

Comments
 (0)