This is my second VUE web application deploy which I can't access. Inside Docker host Linux running curl localhost:8081, curl: (56) Recv failure: Connection reset by peer
Dockerfile:
FROM node:12
WORKDIR /app_teste
COPY package*.json ./
RUN npm --version
RUN npm install
COPY . .
EXPOSE 8081
CMD ["npm","run","serve"]
dockercompose.yml:
version: '3'
services:
website:
build: .
ports:
- "8081:8081"
container_name: dexter_g_website
I was reading here some topics similars which says about binding to 0.0.0.0 would work, however it never happens. Anyone can help/suggest anything?
docker port dexter_g_webiste
8081/tcp -> 0.0.0.0:8081
Based on Vue CLI documentation, the default port for serve command is 8080.
If you want to serve it to port 8081, try
CMD npm run serve --port 8081
Some more debugging tips:
You can run curl command inside the docker container to debug your app.
SSH into the running container
docker-compose exec -it <container_id> sh
Install CURL
curl the URL and see which is working
curl http://localhost:8080
curl http://localhost:8081
Related
I want to run a node.js app in a docker container using docker-compose. The app is TiddlyWiki, there are other containers and the whole thing runs in a vagrant VM and is set up with ansible, but I don't think any of that matters for this problem.
This is my docker-compose config:
wiki:
image: node:12-alpine
container_name: nodejs
restart: always
working_dir: /home/node/app
environment:
NODE_ENV: production
volumes:
- "/srv/docker_wiki/:/home/node/app"
ports:
- "8080:8080"
command: "node node_modules/tiddlywiki/tiddlywiki.js mywiki --listen debug-level=debug"
The app seems to start up and run without issues:
vagrant#vserver:~$ sudo docker logs nodejs
Serving on http://127.0.0.1:8080
(press ctrl-C to exit)
syncer-server-filesystem: Dispatching 'save' task: $:/StoryList
But I cannot reach it:
vagrant#vserver:~$ curl http://localhost:8080
curl: (52) Empty reply from server
vagrant#vserver:~$ curl http://localhost:8080
curl: (56) Recv failure: Connection reset by peer
It seems random which of the two different error messages comes up.
An interesting detail: If I use the default node image which comes itself with curl, then I can in fact reach the app from within the container itself after running docker exec -it nodejs /bin/bash
I have also tried to use a different port on the host, with the same result.
Any idea what could be going wrong here?
An interesting detail: If I use the default node image which comes
itself with curl, then I can in fact reach the app from within the
container itself after running docker exec -it nodejs /bin/bash
If you are able to access inside the container, it means the application bind with 127.0.0.1 the localhost of the container.
Serving on http://127.0.0.1:8080
(press ctrl-C to exit)
All need to bind it with 0.0.0.0.
so change the command to
command: "node node_modules/tiddlywiki/tiddlywiki.js mywiki --host 0.0.0.0 --listen debug-level=debug"
or
command: "node node_modules/tiddlywiki/tiddlywiki.js mywiki --listen debug-level=debug host=0.0.0.0"
You explore further ListenCommand here.
I started to work with docker. I dockerized simple node.js app. I'm not able to access to my container from outside world (means by browser).
Stack:
node.js app with 4 endpoints (I used hapi server).
macOS
docker desktop community version 2.0.0.2
Here is my dockerfile:
FROM node:10.13-alpine
ENV NODE_ENV production
WORKDIR /usr/src/app
COPY ["package.json", "package-lock.json*", "npm-shrinkwrap.json*", "./"]
RUN npm install --production --silent && mv node_modules ../
RUN npm install -g nodemon
COPY . .
EXPOSE 8000
CMD ["npm","run", "start-server"]
I did following steps:
I run from command line from my working dir:
docker image build -t ares-maros .
docker container run -d --name rest-api -p 8000:8000 ares-maros
I checked if container is running via docker container ps
Here is the result:
- container is running
I open the browser and type 0.0.0.0:8000 (also tried with 127.0.0.1:8000 or localhost:8000)
result:
So running docker container is not rechable by browser
I also go into the container typing docker exec -it 81b3d9b17db9 sh and try to reach my node-app inside of container via wget/curl and that's works. I get responses fron all node.js endpoints.
Where could be the problem ? Maybe my mac can blocked connection ?
Thanks for help.
Please check the order of the parameters of the following command:
docker container run -d --name rest-api -p 8000:8000 ares-maros
I faced a similar. I was using -p port:port at the end of the command. Simply moving it to after 'Docker run' solved it for me.
I am very to new Docker so please pardon me if this this is a very silly question. Googling hasn't really produced anything I am looking for. I have a very simple Dockerfile which looks like the following
FROM node:9.6.1
RUN mkdir /usr/src/app
WORKDIR /usr/src/app
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
COPY . /usr/src/app
RUN npm start
EXPOSE 8000
In the container the app is running on port 8000. Is it possible to access port 8000 without the -p 8000:8000? I just want to be able to do
docker run imageName
and access the app on my browser on localhost:8000
By default, when you create a container, it does not publish any of its ports to the outside world. To make a port available to services outside of Docker, or to Docker containers which are not connected to the container’s network, use the --publish or -p flag. This creates a firewall rule which maps a container port to a port on the Docker host.
Read more: Container networking - Published ports
But you can use docker-compose to set config and run your docker images easily.
First installing the docker-compose. Install Docker Compose
Second create docker-compose.yml beside the Dockerfile and copy this code on them
version: '3'
services:
web:
build: .
ports:
- "8000:8000"
Now you can start your docker with this command
docker-compose up
If you want to run your services in the background, you can pass the -d flag (for “detached” mode) to docker-compose up -d and use `docker-compose ps to see what is currently running.
Docker Compose Tutorial
Old question but someone might find it useful:
First get the IP of the docker container by running
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name_or_id
Then connect to it from the the browser or using curl using the IP and port exposed :
Note that you will not be able to access the container on 0.0.0.0 because port is not mapped
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
question:
I've created a simple site using Docker and Aurelia. The site runs in Docker, but is not accessible from my localhost. What I did:
create container
docker build -t randy/node-web-app .
docker run -p 9000:9000 -d randy/node-web-app
97f57c3d0da5d03f53b4ba893fdb866ca528e10e6c4a1b310726e514d8957650
see if the scripts ran:
docker logs 97f57c3d0da5
Application Available At: http://localhost:9000
Going into docker container terminal to see if the site is up:
docker exec -it 97f57c3d0da5 /bin/bash
See if it runs:
curl -i localhost:9000
summary:
HTTP/1.1 200 OK
<!DOCTYPE html>
(I actually see the HTML that it should return, but that's too big to post here.)
return to host terminal:
exit
curl -i localhost:9000
curl: (7) Failed to connect to localhost port 9000: Connection refused
How can I make sure I can access that site from my pc? In the first command, I've set expose on 9000:9000 so that shouldn't be a problem.
Dockerfile:
FROM node:latest
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY . /usr/src/app
RUN npm install -g aurelia-cli
RUN npm install
EXPOSE 9000
CMD ["npm", "start"]
I used Kitematic instead of the normal version of Docker on the machine where I deployed this image. Kitematic maps the docker image to an (internal) IP address instead of the localhost of the host machine.
My answer was to use 192.168.1.67 as IP instead of 127.0.0.1.
If you install Docker without Kitematic, this should not be an issue.