Docker service not running container - node.js

I need help understanding why my dockerfile does not work properly.
I created the image which I called hello-nodemon:
FROM node:latest
ENV HOME=/src/jv-agricultor
RUN mkdir -p $HOME/
WORKDIR $HOME/
ADD package* $HOME/
RUN npm install
EXPOSE 3000
ADD . $HOME/
CMD ["npm", "start"]
it works because when I run docker run -p 3000:3000 it works perfectly. But I want to use docker-compose.yml:
version: "3"
services:
web:
image: hello-nodemon
deploy:
replicas: 5
resources:
limits:
cpus: "0.1"
memory: 50M
restart_policy:
condition: on-failure
ports:
- "3000:3000"
networks:
- webnet
networks:
webnet:
So i used the commands: docker stack deploy -c docker-compose.yml webservice this return me:
ID NAME MODE REPLICAS IMAGE PORTS
y0furo1g22zs webservice_web replicated 5/5 hello-nodemon:latest *:3000->3000/tcp
So docker service ps y0furo1g22zs return me:
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
nbgq8ln188dm webservice_web.1 hello-nodemon:latest abner Running Running 4 minutes ago
rrxjwudtorsm webservice_web.2 hello-nodemon:latest abner Running Running 4 minutes ago
7qrz9gtd4fan webservice_web.3 hello-nodemon:latest abner Running Running 4 minutes ago
lljmj01zlya8 webservice_web.4 hello-nodemon:latest abner Running Running 4 minutes ago
raqw3z0pdxqt webservice_web.5 hello-nodemon:latest abner Running Running 4 minutes ago
My containers
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6daf6afadfdc hello-nodemon:latest "npm start" 6 minutes ago Up 6 minutes 3000/tcp webservice_web.1.nbgq8ln188dmz8q8qeb60scbz
2d74f8e9a728 hello-nodemon:latest "npm start" 6 minutes ago Up 6 minutes 3000/tcp webservice_web.2.rrxjwudtorsm6to56t0srkzda
e3a3a039fdf9 hello-nodemon:latest "npm start" 6 minutes ago Up 6 minutes 3000/tcp webservice_web.3.7qrz9gtd4fanju4zt6zx3afsf
7f08dbdf0c8d hello-nodemon:latest "npm start" 6 minutes ago Up 6 minutes 3000/tcp webservice_web.5.raqw3z0pdxqtvkmkp00bp6tve
c6ce3762d6ae hello-nodemon:latest "npm start" 6 minutes ago Up 6 minutes 3000/tcp webservice_web.4.lljmj01zlya89gvmip5z0cf6f
but it does not work. The browser does not refuse but does not load the page; is infinitely searching.
I do not know what is happening, if someone helps me I will be very grateful.

This seems to be an issue with chrome only. I have the same issue in chrome, however, when I open in Firefox it works fine.
Here's how I fixed Chrome:
Looking into this more I think this was either and chrome issue or network issue as I was having the same issue:
Here is how I resolved it:
Make sure your /etc/hosts file has 127.0.0.1 localhost (more than likely it's already there)
Cleared Cookies and Cached files
Cleared host cache
Go to:chrome://net-internals/#dns click Clear Host Cache
Restarted chrome
Reset Network Adapter
Note: This was unintentional so not sure if it was part of the fix or not, but wanted to include it in case.
Unfortunately I'm not sure which step fixed the problem

Related

Why does my docker processes keep restarting on my Raspberry Pi?

I'm attempting to use deluge on my Raspberry Pi.
I've followed the guide as per: https://hub.docker.com/r/linuxserver/deluge
I've created a docker-compose.yml file which consists of the following:
version: "2.1"
services:
deluge:
image: lscr.io/linuxserver/deluge:latest
container_name: deluge
environment:
- PUID=1000
- PGID=1000
- TZ=Europe/London
- DELUGE_LOGLEVEL=error #optional
volumes:
- /path/to/deluge/config:/config
- /path/to/your/downloads:/downloads
ports:
- 8112:8112
- 6881:6881
- 6881:6881/udp
restart: unless-stopped
I can run the above using the command docker compose up -d
Once the service is running I check it using docker ps which shows the following:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2524b4bb191b lscr.io/linuxserver/deluge:latest "/init" 5 minutes ago Restarting (111) 2 seconds ago deluge
When running docker ps sometimes it shows the following:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2524b4bb191b lscr.io/linuxserver/deluge:latest "/init" 5 minutes ago Up Less than a second 0.0.0.0:6881->6881/tcp, :::6881->6881/tcp, 58846/tcp, 0.0.0.0:8112->8112/tcp, 0.0.0.0:6881->6881/udp, :::8112->8112/tcp, :::6881->6881/udp, 58946/tcp, 58946/udp deluge
But, soon after it shows the following again:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2524b4bb191b lscr.io/linuxserver/deluge:latest "/init" 7 minutes ago Restarting (111) 55 seconds ago deluge
Hence I cannot remote into it via a browser.
Any ideas anybody? I'm pulling my hair out!!!
There was clearly a corruption in my docker.
I was about to "nuke" my Pi and re-image it but decided to following this YouTube video verbatim before doing so: https://www.youtube.com/watch?v=3ahV7DD_Oxk&t=310s
This fixed the issue and now deluge is always up in docker.

Remove Gitlab docker containers

Recently i tried to install Gitlab on Ubuntu machine using docker and docker-compose. This was only done for testing so i can later install it on other machine.
However, i have a problem with removing/deleting gitlab containers.
I tried docker-compose down and killing all processes related to gitlab containers but they keep restarting even if i somehow manage to delete images.
This is my docker-compose.yml file
version: "3.6"
services:
gitlab:
image: gitlab/gitlab-ee:latest
ports:
- "2222:22"
- "8080:80"
- "8081:443"
volumes:
- $GITLAB_HOME/data:/var/opt/gitlab
- $GITLAB_HOME/logs:/var/log/gitlab
- $GITLAB_HOME/config:/etc/gitlab
shm_size: '256m'
environment:
GITLAB_OMNIBUS_CONFIG: "from_file('/omnibus_config.rb')"
configs:
- source: gitlab
target: /omnibus_config.rb
secrets:
- gitlab_root_password
gitlab-runner:
image: gitlab/gitlab-runner:alpine
deploy:
mode: replicated
replicas: 4
configs:
gitlab:
file: ./gitlab.rb
secrets:
gitlab_root_password:
file: ./root_password.txt
Some of the commands i tried to kill processes:
kill -9 $(ps aux | grep gitlab | awk '{print $2}')
docker rm -f $(docker ps -aqf name="gitlab") && docker rmi --force $(docker images | grep gitlab | awk '{print $3}')
I also tried to update containers with no restart policy:
docker update --restart=no container-id
But nothing of this seems to work.
This is docker ps response:
591e43a3a8f8 gitlab/gitlab-ee:latest "/assets/wrapper" 4 minutes ago Up 4 minutes (health: starting) 22/tcp, 80/tcp, 443/tcp mystack_gitlab.1.0r77ff84c9iksmdg6apakq9yr
6f0887a8c4b1 gitlab/gitlab-runner:alpine "/usr/bin/dumb-init …" 16 minutes ago Up 16 minutes mystack_gitlab-runner.3.639u8ht9vt01r08fegclfyrr8
73febb9bb8ce gitlab/gitlab-runner:alpine "/usr/bin/dumb-init …" 16 minutes ago Up 16 minutes mystack_gitlab-runner.4.m1z1ntoewtf3ipa6hap01mn0n
53f63187dae4 gitlab/gitlab-runner:alpine "/usr/bin/dumb-init …" 16 minutes ago Up 16 minutes mystack_gitlab-runner.2.9vo9pojtwveyaqo166ndp1wja
0bc954c9b761 gitlab/gitlab-runner:alpine "/usr/bin/dumb-init …" 16 minutes ago Up 16 minutes mystack_gitlab-runner.1.pq0njz94v272s8if3iypvtdqo
Any ideas of what i should be looking for?
I found the solution. Problem was that i didn't use
docker-compose up -d
to start my containers. Instead i used
docker stack deploy --compose-file docker-compose.yml mystack
as it is written in documentation.
Since i didn't know much about docker stack, i did a quick internet search.
This is the article that i found:
https://vsupalov.com/difference-docker-compose-and-docker-stack/
The Difference Docker stack is ignoring “build” instructions. You
can’t build new images using the stack commands. It need pre-built
images to exist. So docker-compose is better suited for development
scenarios.
There are also parts of the compose-file specification which are
ignored by docker-compose or the stack commands.
As i understand, the problem is that stack only uses pre-built images and ignores some of the docker-compose commands such as restart policy.
That's why
docker update --restart=no container-id
didn't work.
I still don't understand why killing all the processes and removing containers/images didn't work. I guess there must be some parent process that i didn't found.

setup django on docker

I am new to docker and trying to steup my django project using docker first time.
I am following https://docs.docker.com/compose/django/
Below are the files and their conents that am using.
am using Ubuntu 16
Dockerfile
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/
docker-compose.yml
version: '3'
services:
db:
image: mysql
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
requirements.txt
Django>=2.0,<3.0
psycopg2>=2.7,<3.0
I ran the below command
docker-compose run web django-admin startproject composeexample .
I have doubt in the below output:
.....:~/docker_practice$ docker images -a
REPOSITORY TAG IMAGE ID CREATED SIZE
docker_practice_web latest be61fbfc4d9e 49 seconds ago 960MB
<none> <none> e73f8a4d68de 52 seconds ago 960MB
<none> <none> 7b597f9f4615 About a minute ago 918MB
<none> <none> 0eaf59a89be4 About a minute ago 918MB
<none> <none> cc42d26c3cfb About a minute ago 918MB
<none> <none> ae64e2080658 About a minute ago 918MB
python 3 02d2bb146b3b 11 days ago 918MB
mysql latest b8fd9553f1f0 12 days ago 445MB
.......:~/docker_practice$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker_practice_web latest be61fbfc4d9e 52 seconds ago 960MB
python 3 02d2bb146b3b 11 days ago 918MB
mysql latest b8fd9553f1f0 12 days ago 445MB
When I run "docker images -a" It display 5 images with name as
What this images are?
where does it coming from ?
the command docker images -a will show you also intermediate images, which is hidden in default using docker images
see this

Can't ping running server within container from localhost

I have a running service within a container on my localhost machine
I Can't establish a connection with it even though I specified the port mapping within my docker-compose.yml here it is
version: '2.1'
services:
users-db:
container_name: users-db
build: ./services/users-service/src/db
ports:
- '27017:27017'
volumes:
- './services/users-service/src/db/:/data/db'
users-service:
container_name: users-service
build: './services/users-service/'
volumes:
- './services/users-service:/usr/src/app'
- './services/users-service/package.json:/usr/src/package.json'
ports:
- '3000:3000'
environment:
- NODE_ENV=test
- JWT_SECRET=fuckOffChinese
depends_on:
users-db:
condition: service_started
presence_db:
image: redis
presense_service:
container_name: presense_service
build: './services/presence-service/'
ports:
- "8081:8081"
environment:
- JWT_SECRET=thirdEyeSecret
- PORT=8081
volumes:
- './services/presence-service:/usr/src/app'
- './services/presence-service/package.json:/usr/src/package.json'
depends_on:
- presence_db
this is the command that I use to run this service
docker-compose run presense_service
and this is what I get every time I try to ping it from the terminal by simply doing an HTTP GET request
http: error: ConnectionError: HTTPConnectionPool(host='localhost', port=8081): Max retries exceeded with url: / (Caused by
NewConnectionError(': Failed to establish a new connection: [Errno
61] Connection refused',)) while doing GET request to URL:
http://localhost:8081/
I'm running macOS 10.13.5 and the server start noramally and here is the logs of it
> users-service#1.0.0 start /usr/src
> gulp --gulpfile app/gulpfile.js
[10:12:46] Working directory changed to /usr/src/app
[10:12:52] Using gulpfile /usr/src/app/gulpfile.js
[10:12:52] Starting 'start'...
[10:12:56] Finished 'start' after 3.99 s
[10:12:56] Starting 'lint'...
[10:12:57] Finished 'lint' after 239 ms
[10:12:57] Starting 'default'...
[10:12:57] Finished 'default' after 131 μs
[10:12:57] [nodemon] 1.18.2
[10:12:57] [nodemon] to restart at any time, enter `rs`
[10:12:57] [nodemon] watching: *.*
[10:12:57] [nodemon] starting `node ./index.js`
Server listening on: http://localhost:8081
Redis client connected
Try docker-compose run presense_service --service-ports, or better, use docker-compose up.
docker-compose run specifically doesn't apply the ports from your Compose file to "prevent port collisions with already-open ports" [1] - so you have to add this option, or specify them manually with the same options you would pass to docker run.
Ideally, use docker-compose up -d and then docker-compose logs -f presense_service to get logs. Shut your application down with docker-compose down.
If you really need to, you can comment services out of your docker-compose.yml file that you don't want started.
If you didn't know, the latest version of the compose format is 3.6 - 2.1 is over two years old (released with Docker v1.12.0 on 201607/28 [2]).
Proving this is easy - since I didn't have your code, I replaced all the image/build lines with image: nginx (and took the host path off any volumes).
Example modified compose file (just for reference):
version: '2.1'
services:
users-db:
container_name: users-db
image: nginx
ports:
- '27017:27017'
volumes:
- './services/users-service/src/db/:/data/db'
users-service:
container_name: users-service
image: nginx
volumes:
- '/usr/src/app'
- '/usr/src/package.json'
ports:
- '3000:3000'
environment:
- NODE_ENV=test
- JWT_SECRET=fuckOffChinese
depends_on:
users-db:
condition: service_started
presence_db:
image: redis
presense_service:
container_name: presense_service
image: nginx
ports:
- "8081:8081"
environment:
- JWT_SECRET=thirdEyeSecret
- PORT=8081
volumes:
- '/usr/src/app'
- '/usr/src/package.json'
depends_on:
- presence_db
Running docker ps after docker-compose up -d gives this (pay attention to the PORTS column):
my-machine$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f1b89cf3d6c2 nginx "nginx -g 'daemon of…" 19 seconds ago Up 14 seconds 80/tcp, 0.0.0.0:3000->3000/tcp users-service
be0e9b2bb005 nginx "nginx -g 'daemon of…" 19 seconds ago Up 13 seconds 80/tcp, 0.0.0.0:8081->8081/tcp presense_service
2efed2546926 nginx "nginx -g 'daemon of…" 20 seconds ago Up 14 seconds 80/tcp, 0.0.0.0:27017->27017/tcp users-db
c7a88a84f422 redis "docker-entrypoint.s…" 20 seconds ago Up 14 seconds 6379/tcp test_presence_db_1
...so there's nothing wrong with your port configuration. docker ps after docker-compose run presense_service, then, shows:
my-machine$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
89e4a4f90a75 nginx "nginx -g 'daemon of…" 28 seconds ago Up 21 seconds 80/tcp test_presense_service_run_1
2c91fcb5091d redis "docker-entrypoint.s…" 29 seconds ago Up 24 seconds 6379/tcp test_presence_db_1
...and therefore it was your command causing the problem. Happy to help as I've learnt something new :)
[1] https://docs.docker.com/compose/reference/run/
[2] https://docs.docker.com/release-notes/docker-engine/#1120-2016-07-28
Try this to find out if port 8081 is open/occupied:
netstat -l | grep 8081
When your server logs say
Server listening on: http://localhost:8081
The server will be inaccessible outside the Docker container. It looks like this is the default behavior of the Express JavaScript Web server, and many other frameworks when run in “developer” mode. You need to set the server to listen on all IP addresses, probably by passing 0.0.0.0 as the “bind” address. (Note that you cannot connect to 0.0.0.0, and saying “listen to 0.0.0.0” means “accept connections from anywhere”.
If your server is in fact based on Express, https://superuser.com/questions/582624/how-to-access-nodejs-server-on-lan might be informative to you.

Exposing docker container on local server

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.

Resources