When I run following commands, I can access 127.0.0.1:80 at localhost successfully.
docker run -p 127.0.0.1:80:80 --name Mynginx -dt nginx
docker exec -it Mynginx bash
But If I run the commands at digitalocean's DROPLETS, how to access it now? ( I tried to access DROPLETS's IP address:80, but I get nothing.)
You need to EXPOSE
the port. See the documentation for more information on how.
If you run the containers from the command-line, you can map the ports with the -p tag. You can map multiple ports.
docker run -dt -p 80:80 --name Mynginx nginx
or
docker run -dt -p 80:80 -p 443:443 --name Mynginx nginx
If you're using docker-compose, you can add the EXPOSE
tag in your yaml file.
version: '2.3'
services:
my_container:
container_name: "Mynginx"
image: nginx:latest
expose:
- "80"
You need to update your droplets firewall settings to allow incoming connections to port :80
. To update this select your droplet.
Then go to Networking
-> Manage Firewalls
-> Create Firewall
Then under Inbound Rules
create a new HTTP
rule by selecting HTTP
from the dropdown menu. Scroll down and apply this firewall to your droplet, then you should be able to receive inbound traffic on port :80
. You will have to add a similar rule for any other ports you want to open up.
See here for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With