Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play with docker - access IP address on webbrowser

Tags:

docker

I am practising building web apps on play with Docker (https://www.docker.com/play-with-docker) . My Dockerfile looks like

# Test web-app to use with Pluralsight courses and Docker Deep Dive book
# Linux x64
FROM alpine

LABEL maintainer="[email protected]"

# Install Node and NPM
RUN apk add --update nodejs nodejs-npm

# Copy app to /src
COPY . /src

WORKDIR /src

# Install dependencies
RUN  npm install

EXPOSE 8080

ENTRYPOINT ["node", "./app.js"]

Taken from https://github.com/nigelpoulton/psweb/blob/master/Dockerfile. I can build the image and run a container off it, however I am struggling to view the application.

    docker container run -d —name web1 -p 8080:8080 psweb

When running off my local terminal, I can see it on localhost:8080 but I do not know which (if it is possible) IP I need to go to see it in a web browser.

On the play with docker UI, there is an IP address 123.456.7.89 and I click Open Port, give it 8080 but I still cannot reach it. Any help with this would be hugely appreciated! Currently I am trying to access 123.456.7.89:8080

Apologies if I am missing something obvious, still very new to docker/webapps

like image 592
greenPlant Avatar asked Oct 24 '25 10:10

greenPlant


2 Answers

To access your web application in the browser, you'll have to click on the port displayed beside the (internal) IP address.

See here:

enter image description here

This will take you to a complex URL that resolves to the IP:Port of your web app (something akin to http://ip172-18-0-70-brti9kosm4g00eh6pmg-8080.direct.labs.play-with-docker.com).

like image 143
rachidbch Avatar answered Oct 26 '25 23:10

rachidbch


The container is exposing the port 8080 and the docker run line sets up a port forwarding from the port 8080 of the host machine to the port 8080 of the container.

If the browser is on the same computer, you should be able to access the node server by writing http://localhost:8080 in the address bar.

You should also be able to access it if you put 127.0.0.1 (or any other address your computer has, eg: IP of your Wifi adapter) instead of localhost.

With that being said, there is a way for you to know the actual IP of the container:

docker inspect postgres | grep 'IPAddress'
like image 38
JuanR Avatar answered Oct 26 '25 23:10

JuanR