Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access docker container at digitalocean?

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.)

like image 421
jimmy Avatar asked Sep 02 '25 15:09

jimmy


2 Answers

You need to EXPOSE the port. See the documentation for more information on how.

Running from the command-line

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

Docker-compose

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"
like image 177
d00dle Avatar answered Sep 05 '25 15:09

d00dle


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.

like image 24
Jack Avatar answered Sep 05 '25 14:09

Jack