Home > database >  Accessing A Web App Running In Docker From Another Machine
Accessing A Web App Running In Docker From Another Machine

Time:07-31

I've cloned the following dockerized MEVN app and would like to access it from another PC on the local network.

The box that docker is running on has an ip of 192.168.0.111 but going to http://192.168.0.111:8080/ from another PC just says it can't be reached. I run other services like plex and a minecraft server that can be reached with this ip so I assume it is a docker config issue. I am pretty new to docker.

Here is the Dockerfile for the poral. I made a slight change from the repo adding -p 8080:8080 because I read elsewhere that it would open it up to lan access.

FROM node:16.15.0

RUN mkdir -p /usr/src/www &&
apt-get -y update &&
npm install -g http-server

COPY . /usr/src/vue WORKDIR /usr/src/vue RUN npm install RUN npm run build RUN cp -r /usr/src/vue/dist/* /usr/src/www

WORKDIR /usr/src/www EXPOSE 8080 CMD http-server -p 8080:8080 --log-ip

CodePudding user response:

Don't put -p 8080:8080 in the Dockerfile!

You should first build your docker image using docker build command.

docker build -t myapp .

once you've built the image, and confirmed using docker images you can run it using docker run command

docker run -p 8080:8080 myapp

CodePudding user response:

Docker listens 0.0.0.0 IP address and the other machines on the same network can use your ip address to show your website on which port did you use for sharing. For example you use 8080 and actually you listen 0.0.0.0:8080 and the other machines http://192.168.0.111:8080/ can reach that website with your ip address. Without docker you can also listen 0.0.0.0 to share your app on network.

CodePudding user response:

The box that docker is running on

  1. What u mean by saying "BOX"? Is it some kind of virtual box or maybe actual computer with Linux or Windows or maybe MacOS?

  2. Have u checked particular "BOX"'s firewall? (u may need to do "NAT" over firewall to particular in "BOX" running service for incoming requests from outside of "BOX").

I'll be happy to help u our if u'll provide more detailed information about your environment...

  • Related