I have a properly installed copy of Docker CE on my Windows 10 Pro machine.
I am trying to run a simple node app using docker-compose and be able to dynamically update the code while running in docker. I followed this website to build it out, and my code can be found here.
When I navigate to localhost:8080 while running the code locally, I get my web page. When I run it through Docker, I get "This page isn't working" from my web browser (same url). I have made sure to stop running locally before running in Docker so that the ports aren't crossed.
My Dockerfile:
FROM node:6.10.2
RUN useradd --user-group --create-home --shell /bin/false app
ENV HOME=/home/app
COPY package.json npm-shrinkwrap.json $HOME/diet-program/
RUN chown -R app:app $HOME/*
USER app
WORKDIR $HOME/diet-program
RUN npm install
EXPOSE 8080
CMD ["npm", "run", "dev"]
My docker-compose.yml:
version: '2'
services:
diet-program:
build: .
ports:
- "8080:8080"
volumes:
- .:/home/app/diet-program
- /home/app/diet-program/node_modules
The dev command is mapped to: webpack-dev-server --content-base src --inline --hot
For expose ports try to change line
ports:
- 8080:8080
into
ports:
- "8080:8080"
in docker-compose.yml file
More details about expose ports here: https://docs.docker.com/compose/compose-file/#ports
For check if you call a correct IP check with command docker inspect <container_name> in "NetworkSettings" and look at IPAddress.
Related
So, this is the first problem that I didn't find any answer around the internet.
So, basically I have a redbird app that works as expected and i decided to put it inside a Docker container (don't wanna run screen or tmux, etc).
So i created a Dockerfile as follow:
FROM node:alpine
WORKDIR /var/WebService/apps/redbird
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 80 443
CMD ["node", "app"]
and a docker-compose.yml as follow:
version: "3"
services:
redbird:
container_name: redbird
build: .
command: npm start
ports:
- "80"
- "443"
environment:
NODE_ENV: PRODUCTION
and it doesn't work.
My thoughts are:
Docker does not have access to port 80 and 443. (yes, i'm running as root and i know it is not recommended).
Docker is not mapping the ports inside the container to my external LAN.
And, why people are not talking about redbird? i found 0 help about redbird.
You don't need docker-compose to execute a docker container. You also have images of redbird at dockerhub such as https://hub.docker.com/r/myuserindocker/redbird-reverseproxy.
docker run --rm -p 80:80 -p 443:443 myuserindocker/redbird-reverseproxy
I'm relatively new to docker and I've been having a really strange problem.
The docker setup I have below runs perfectly, however though there seems to be an instance that is always running even after stopping and removing all containers and quitting the docker application.
When I access localhost in my browser, My app is always live and running.
I've tried running docker-compose stop ; docker-compose rm to stop and remove all container.
'docker-compose ps' and 'docker ps' both show no containers running at all. But whenever I access localhost, my app is there live and running.
Like i said i have tried quitting the docker application (I'm running on mac). i tried restarting the machine and the app would still be running.
The weird thing is when i check to see which if any processes are using port 80 (thus making my app accessible via localhost) by running 'sudo lsof -i tcp:80' the list is empty.
I'm new to docker and I know there must be something I'm overlooking.
Thanks in advance, any help and ideas are welcomed.
Here is my folder structure: screenshot
The Dockerfile for my app:
FROM node:10
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
EXPOSE 3000
ENV NUXT_HOST=0.0.0.0
ENV NUXT_PORT=3000
CMD [ "npm", "start" ]
docker-compose.yml
version: '3'
services:
nuxt:
build: ./app/
container_name: nuxt
restart: always
ports:
- '1880:1880'
command: 'npm run start'
nginx:
image: nginx:1.13
container_name: nginx
ports:
- '80:80'
volumes:
- ./nginx:/etc/nginx/conf.d
depends_on:
- nuxt
This is a question specifically for the tutorial at: http://mherman.org/blog/2017/12/07/dockerizing-a-react-app/#.Wv3u23WUthF by Michael Herman
Problem: The app starts inside the container, but it is not accessible from the port I just exposed -p 3000:3000. When Browse to localhost:3000 get a This site can’t be reached error
docker-compose.yaml
version: '3.5'
services:
sample-app:
container_name: sample-app
build:
context: .
dockerfile: Dockerfile
volumes:
- '.:/usr/src/app'
- '/usr/src/app/node_modules'
ports:
- '3000:3000'
environment:
- NODE_ENV=development
Dockerfile
# base image
FROM node:9.6.1
# set working directory
RUN mkdir /usr/src/app
WORKDIR /usr/src/app
# add `/usr/src/app/node_modules/.bin` to $PATH
ENV PATH /usr/src/app/node_modules/.bin:$PATH
# install and cache app dependencies
COPY package.json /usr/src/app/package.json
RUN npm install --silent
# RUN npm install react-scripts#1.1.1 -g --silent # Uncomment to silent logs
RUN npm install react-scripts#1.1.1 -g
# start app
CMD ["npm", "start"]
#CMD tail -f /usr/src/app/README.md
###################################
# To Run sample app:
# docker run -it -v ${PWD}:/usr/src/app -v /usr/src/app/node_modules -p 3000:3000 --rm sample-app
Docker logs : https://docs.google.com/document/d/14LRCgjMLAkmdMiuedxAW2GWUAtxmWeJQCNQB2ezdYXs/edit
After running either the compose or single container. It shows successful startup, but nothing thereafter.
When I docker exec into the container, $ curl localhost:3000 returns the proper index.html page
I start up the container with either:
$ docker run -it -v ${PWD}:/usr/src/app -v /usr/src/app/node_modules -p 3000:3000 --rm sample-app
<- (The image sample-app exists )
or
$ docker-compose up
After eliminating all other factors I assume that your application is listening on localhost. Localhost is scoped to the container itself. Therefore to be able to connect to it, you would have to be inside the container.
To fix this, you need to get your application to listen on 0.0.0.0 instead.
The problem is your are exposing the app on localhost strictly.
You have to modify your package.json to change that:
"start": "http-server -a localhost -p 3000"
into:
"start": "http-server -a 0.0.0.0 -p 3000"
if your contents of package.json differ strongly from that what's above, the important part is the -a option - it has to point to 0.0.0.0 as it means the http-server will listen on all incoming connections.
If you are not sure what to change, just post the essential part of package.json here in your question so we can check it.
I had the same issue when I was using create-react-app but I managed to solve it by not exposing the docker port in the Dockerfile and running the following command docker container run -p ANY_PORT_YOU_WANT:**3000** -d image_name. It so happens that by default react-server runs on PORT 3000 in the docker container and by exposing any other port other than 3000, that connection flow is killed. The start script uses 0.0.0.0 by default. See Issue
I have a web application written in Node.js that I'm trying to get into Docker. Running the image with docker run -p 80:80 image works just fine; I'm able to access the webpage it's hosting. However, when I try to run it in a stack, I'm unable to access the page, and Chrome just sits "Waiting for localhost..." forever.
Dockerfile:
FROM readytalk/nodejs
WORKDIR /app
ADD . /app
RUN npm i
EXPOSE 80
CMD []
ENTRYPOINT ["/nodejs/bin/npm", "start"]
docker-compose.yml:
version: "3"
services:
web:
image: image_name
deploy:
replicas: 5
resources:
limits:
cpus: "0.1"
memory: 50M
restart_policy:
condition: on-failure
ports:
- "80:80"
networks:
- webnet
networks:
webnet:
Any help would be greatly appreciated.
EDIT: Added some logging and it seems that the HTTP request is never actually making it to the Node.js app. It seems like Docker has recieved the request, but hasn't routed it to the running app.
Some time your docker container run your IP address.
you can check it by running this command docker info
second option
Go to terminal and write
in window
ipconfig
and see preferred IP then access your container with that IP with specifying port
in Ubuntu
ifconfig
Hope this will solve your problem and try to access using 127.0.0.1:port
You can check this slide which shows and run hello world node+docker
docker-node-hello-world-application
And I will recommend using this Docker file.
Node_DockerFile
FROM alpine
RUN apk update && apk upgrade
RUN apk add nodejs
RUN mkdir -p /app
ADD app/package.json /app
WORKDIR /app/
ENV HOME /app
ENV NODE_ENV development
RUN npm install
ADD app /app
EXPOSE 3000
CMD npm start
I have a nodejs-mongo db app that is running inside docker containers.
I can access it on localhost etc...
But now I would like to install/deploy these containers on a local server, so that I can access this application outside my network.
Please note my server is Ubuntu 16.04.1 LTS (xenial)
Also I would like to access Db from outside, so that I can send data to the Db using custom script.
I am newbie in both networking and Docker. As a result I am struggling to understand what needs to be done. Any pointers would be appreciated
Here is the docker-compose.yml
version: "2"
services:
web:
build: .
volumes: # Use this to mount app from local disk
- ./:/usr/src/app
ports:
- "8080:8080"
- "5858:5858"
entrypoint: node --debug=5858 app.js
links:
- mongo
mongo:
image: mongo
ports:
- "27017:27017"
Here is my Dockerfile
FROM node:argon
# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# Install app dependencies
COPY package.json /usr/src/app/
RUN npm install
# Bundle app source
COPY . /usr/src/app
EXPOSE 8080
CMD [ "npm", "start" ]
Usual command that I give to start my containers docker-compose up --build -d
Here is docker ps result
"node --debug=5858 ap" 13 minutes ago Up 13 minutes 0.0.0.0:5858->5858/tcp, 0.0.0.0:8080->8080/tcp nodemongochart_web_1
"/entrypoint.sh mongo" 13 minutes ago Up 13 minutes 0.0.0.0:27017->27017/tcp nodemongochart_mongo_1
If by local server, you mean your own machine at home, you will need to do something called "Port Forwarding".
It's usually configurable in your router, and you'll be able to access your application via some kind of link like this :
http://you-personal-ip:8080
If you'll be using another host, not in your own network, they should provide you with an IP address, in that case, no need for port forwarding.