Search code examples
postgresqlamazon-web-servicesdockeramazon-ec2pgadmin-4

Unable to access a localhost on ec2 to access pgAdmin container


Here are my steps --

  1. created an ec2 in my public subnet with public address enabled.
  2. allowed the public ip address with all ports as inbound rule on the security group attached to the above ec2.
  3. installed docker
  4. docker pull dpage/pgadmin4 --- created the image
5. docker run -p 80:80 \
    -e '[email protected]' \
    -e 'PGADMIN_DEFAULT_PASSWORD=SuperSecret' \
    -d dpage/pgadmin4
  1. docker ps to confirm that container is running

  2. curl http://localhost or http:127.0.0.1 is failing

  3. From browser public-ip:80 is also failing ( timeout)

Really bothering me and appreciate any help/guidance to resolve.


Solution

  • This sounds like it should work fine, but here are my steps for creating the same setup.

    1. Launch an EC2 instance.
    2. Attach appropriate security groups. I'm assuming that your security groups on the EC2 instance look something like this:

    enter image description here

    This will allow inbound connections on ports 22 (SSH), 80 (HTTP) and 443 (HTTPS) from any external IP.

    1. Create a SSH connection to the EC2 instance. Next few steps are done via the SSH connection.
    2. sudo apt update and sudo apt install docker.io.
    3. Launch container:
    docker run -p 80:80 \
        -e '[email protected]' \
        -e 'PGADMIN_DEFAULT_PASSWORD=SuperSecret' \
        -d dpage/pgadmin4
    
    1. Check that container is running.
    $ docker ps
    CONTAINER ID   IMAGE            COMMAND            CREATED         STATUS         PORTS                                        NAMES
    1bbf1925d84a   dpage/pgadmin4   "/entrypoint.sh"   8 minutes ago   Up 8 minutes   0.0.0.0:80->80/tcp, :::80->80/tcp, 443/tcp   xenodochial_pike
    

    You should also check that the port mapping is correct. It should be 0.0.0.0:80->80/tcp, :::80->80/tcp, 443/tcp.

    1. Check for local connection.
    $ curl http://localhost
    <!doctype html>
    <html lang=en>
    <title>Redirecting...</title>
    <h1>Redirecting...</h1>
    <p>You should be redirected automatically to the target URL: <a href="/login?next=%2F">/login?next=%2F</a>. If not, click the link.
    
    $ curl http://127.0.0.1
    <!doctype html>
    <html lang=en>
    <title>Redirecting...</title>
    <h1>Redirecting...</h1>
    <p>You should be redirected automatically to the target URL: <a href="/login?next=%2F">/login?next=%2F</a>. If not, click the link.
    
    1. Check for remote connection. Try connecting from a browser on your local machine. The public IP for my test EC2 instance is 18.130.230.222, so I went to http://18.130.230.222.

    enter image description here