Unable to access docker container(portainer) on public ip

I have installed manjaro on my old laptop and my friend also have a old laptop we both are trying to make a docker cluster
We have searched on google and chatgpt(from openai) and then we ran the following script

#!/bin/bash

# install Docker
sudo pacman -S docker

# start the Docker daemon
sudo systemctl start docker

# create a Docker swarm
docker swarm init --advertise-addr eth0

# get the join command and save it to a file
JOIN_COMMAND=$(docker swarm join-token worker -q)
echo $JOIN_COMMAND > join_command.txt

# create an overlay network
docker network create --driver overlay my-network

# deploy a service on the cluster
docker service create --name web-server --publish 8080:80 nginx

docker service scale web-server=3

Then i installed portainer

#!/bin/bash

# Create a Portainer container and mount it to the /data directory on the host
docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v /data:/data portainer/portainer
 

I was able to access on my local ip on port 9000
But my friend is not able to access it

I got public ip using

curl ifconfig.me

How can i make my friend access the docker container (portainer) or atleast how can he join the docker cluster?

Thanks in advance

Depends on how you are connected to the internet. For simple Home Internet via Cable or Landline, it usually means to configure port forwarding in your Home Router.

I m connected via wifi , i have only a local ipv4 in it, can u tell me how to configure port forward? I checked on chatgpt and it didn’t work it was

 #!/bin/bash

# Install Docker
apt-get update
apt-get install -y docker.io

# Start Docker service
systemctl start docker

# Create a Portainer container and mount it to the /data directory on the host
docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v /data:/data portainer/portainer

# Set up dynamic DNS
apt-get install -y ddclient

echo "daemon=600
ssl=yes
use=web, web=myip.dnsdynamic.com
server=www.dnsdynamic.com
login=your_login
password='your_password'
your_hostname" > /etc/ddclient.conf

systemctl start ddclient

# Set up port forwarding on the router
# Replace <router_ip> with the IP address of your router
# Replace <local_ip> with the IP address of the machine where Portainer is running
# Replace <port> with the port number on which Portainer is listening (e.g., 9000)

curl -X POST -d '{"port_mappings": [{"local_ip": "<local_ip>", "public_port": <port>, "private_port": <port>, "protocol": "tcp"}]}' http://<router_ip>:8080/v1/port_mappings

# Get the public IP address of the router
PUBLIC_IP=$(curl http://checkip.dyndns.org/ | grep -Eo '[0-9\.]+')

echo "Portainer has been installed and is now running on port 9000."
echo "You can access the Portainer web interface from other networks by going to http://$PUBLIC_IP:<port> in a web browser,"
echo "where <port> is the port number on which Portainer is listening (e.g., 9000)."

EDIT: i just downloaded the package, app given in this script from yay and did the config given in it

No, nearly every Router model is different and need different steps. Most of them can only be configured via a Webinterface. Check out the manual of your Router or get in touch with your ISP.

Ok thanks , but is there a way that i can add a public ipv4 instead of local ip in my current network interface or maybe in a new interface?

Cause when i did docker swarm init on my current interface it was using the local ip it had

setup portforward in router - see router manual

Your home lan - or whatever lan - only has one public IP

  • you cannot add your public ip to your local lan interface
  • you need portforwarding
  • you have to look up how to do it for your router
  • then there is plenty resources
  • you can probably find your router there

Add your router make and model to below search

Thank you so much for the details,

i find out my router port forwarding

  1. i went to 192.168.1.1
  2. then i login with admin pass and username
  3. then i went under port frowarding section i selected 22 port of WLAN and LAN, TCP/UDP and ip of my old laptop which was 192.168.1.5
  4. i added it , it was showing my active

but when i tried to connect it with public ip, i was unable to do so
i check on this site there also it shows port isnt forwarded

i have sshd enabled and started i can connect it with my local ip 192.168.1.5 but not wiht public ip

i tried port forwarding 9000 port which is of docker container it was also not working

can you pls help me solve this porblem