client access to docker swarm - docker

I have a docker swarm cluster consisting of one manager and one worker node. Then I configured (tls and DOCKER_HOST) a client from my laptop to get access to this cluster.
When I run docker ps I see only containers from the worker node (and not all containers of worker node (!)).
For example, from my client:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a129d9402aeb progrium/consul "/bin/start -rejoi..." 2 weeks ago Up 22 hours IP:8300-8302->8300-8302/tcp, IP:8400->8400/tcp, IP:8301-8302->8301-8302/udp, 53/tcp, 53/udp, IP:8500->8500/tcp, IP:8600->8600/udp hadoop1103/consul-agt2-hadoop
As well as I run docker ps at worker node:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4fec7fbf0b00 swarm "/swarm join --advert" 16 hours ago Up 16 hours 2375/tcp join
a129d9402aeb progrium/consul "/bin/start -rejoin -" 2 weeks ago Up 22 hours 0.0.0.0:8300-8302->8300-8302/tcp, 0.0.0.0:8400->8400/tcp, 0.0.0.0:8301-8302->8301-8302/udp, 53/tcp, 53/udp, 0.0.0.0:8500->8500/tcp, 0.0.0.0:8600->8600/udp consul-agt2-hadoop
So two questions: Why docker ps doesn't show containers from manager machine and not all containers from worker node?

Classic swarm (run as a container) by default hides the swarm management containers from docker ps output. You can show these containers with a docker ps -a command instead.
This behavior may be documented elsewhere, but the one location I've seen the behavior documented is in the api differences docs:
GET "/containers/json"
Containers started from the swarm official image are hidden by default, use all=1 to display them.
The all=1 api syntax is the equivalent of the docker ps -a cli.

Related

"docker ps" does not show PORT details of a Kubernetes-controlled container

I have two Redis containers running on a K8s worker node. One is controlled by a Deployment (redisdeploymet1) and the other is a standalone Docker container that I created locally on worker1 (outside the knowledge of K8s)“:
root#worker1:~# docker ps | head -1 ; docker ps | grep redis | grep -v pause
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bc7b6fd74187 redis "docker-entrypoint.s…" 4 minutes ago Up 4 minutes 6379/tcp nervous_vaughan
3c6fc536e265 redis "docker-entrypoint.s…" 42 minutes ago Up 42 minutes k8s_redis_redisdeploymet1-847d97
Why shouldn’t we see the PORT details on both entries above? I have actually tested them; both are indeed listening on 6379.
My ultimate goal is to identify which ports a specific Pod is listening on. Let's say the Dockerfile is not available.
Thanks
You can use docker port command.
docker port <container_id>: List port mappings or a specific mapping for the container

In SWARM not able to access service from worker node

I am new to the docker world. During learning I have created the below setup:
1.Virtual machine - Ubuntu 20 running on VMware workstation 15 Player. IP - 192.168.0.106. I am able to access the internet from this VM(say it VM1) and able to ping that system from my physical system OS( Windows 10)
2.Virtual Machine - Ubuntu 20 running on VMware workstation 15 Player. IP - 192.168.0.105. I am able to access the internet from this VM(say it VM2) and able to ping that system from my physical system OS( Windows 10)
Now I have created the swarm as follows from VM1:
sudo docker swarm init --advertise-addr 192.168.0.106:2377 --listen-addr 192.168.0.106:2377
Then I added the VM2 in this swarm as follows:
sudo docker swarm join --token SWMTKN-1-4i56y47l6o4aycrmg7un21oegmfmwnllcsxaf4zxd05ggqg0zh-9qp67bejerq9dhl3f0suaauvl 192.168.0.106:2377 --advertise-addr 192.168.0.105:2377 --listen-addr 192.168.0.105:2377
After that I checked the swarm details:
sudo docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
ogka7rdjohri9elcbjjcpdlbp * ubuntumaster Ready Active Leader 19.03.12
7qu9kiprcz7oowfk2ol31k1mx ubuntuslave Ready Active 19.03.13
Then deployed the nginx service as follows from VM1:
sudo docker service create -d --name myweb1 --mode global -p9090:80 nginx:1.19.3
Service status:
sudo docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
e1o9cbm3e0t myweb1 global 2/2 nginx:1.19.3 *:9090->80/tcp
Service details:
sudo docker service ps zf6kfw7aqhag
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
egd8oliwngf3 myweb1.ogka7rdjohri9elcbjjcpdlbp nginx:1.19.3 ubuntumaster Running Running 14 minutes ago
1o4q8dlt94jj myweb1.7qu9kiprcz7oowfk2ol31k1mx nginx:1.19.3 ubuntuslave Running Running 14 minutes ago
Now I am able to access the nginx from VM1 using URL: 192.168.0.106:9090 and localhost:9090. But I am not able to access nginx from VM2 using URL: 192.168.0.105:9090 and localhost:9090. My understanding that the nginx are running on both the VMs and can be accessible on both.
in both the VM1 I am able to see the nginx container is running.
VM1 :
sudo docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7a4e13e49dfd nginx:1.19.3 "/docker-entrypoint.…" 16 minutes ago Up 15 minutes 80/tcp myweb1.ogka7rdjohri9elcbjjcpdlbp.egd8oliwngf35wwpjcieew323
VM2:
sudo docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
999062110f0 nginx:1.19.3 "/docker-entrypoint.…" 16 minutes ago Up 16 minutes 80/tcp myweb1.7qu9kiprcz7oowfk2ol31k1mx.1o4q8dlt94jj4uufysnhsbamd
Please guide me on this if I am doing any mistakes.
TIA,
Deb
Problem solved! it was an issue was the ip clashing. Restarted the whole systems including the VM and router to solve this issue.

Creating a docker service is not also creating a docker container

I am trying to create a docker container in a swarm. I am expecting to see the service when I execute "docker service ls", and to see a container running when I execute "docker ps". I see the service but not the container.
[root#docker01-staging dcater]# docker service create --name dbcservice alpine ping 127.0.0.1
lm2b7g3kbnbn11m33y15bplqf
overall progress: 1 out of 1 tasks
1/1: running [==================================================>]
verify: Service converged
[root#docker01-staging dcater]# docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
maad961bcum4 dbcservice replicated 1/1 alpine:latest
[root#docker01-staging dcater]# docker ps --filter name=dbcservice
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
Any idea what I am missing?
I figured out the answer (roughly). I'm not sure I have the terminology right, but docker01-staging is the management node. I checked docker02-staging, and that's actually where the process is running:
[root#docker02-staging dcater]# docker ps --filter name=dbcservice
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3f30b6fa3d40 alpine:latest "ping 127.0.0.1" 56 minutes ago Up 56 minutes dbcservice.1.fke9ljd8brpwzhklzqy0agt1r
docker ps is a docker level command that talks to the docker daemon running on the same node that docker ps is run, whereas in the context of Docker Swarm, docker service is a swarm level command, querying the swarm state. Thus docker ps must always be executed on each node in the swarm to see the running containers.
There is also docker node ps which is a swarm level command that will show the containers running on swarm nodes using the swarm node name. Use docker node ls to show the swarm node names.

Why docker containers can run, despite of docker-machine is not running?

Apparently, this is a silly question, though, i hope someone can help me.
I was thinking docker containers can run, because docker-machine is running on my MacOS X. Like on this situation:
> docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
default - virtualbox Running tcp://192.168.99.100:2376 v1.12.2
> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
abb8beb2a0fd httpd:2.4 "httpd-foreground" 48 minutes ago Up 47 minutes 0.0.0.0:80->80/tcp romantic_kare
But container can run, although in this situation.
> docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
default - virtualbox Stopped Unknown
> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
abb8beb2a0fd httpd:2.4 "httpd-foreground" 48 minutes ago Up 47 minutes 0.0.0.0:80->80/tcp romantic_kare
Are there are no relationships between them?
Reference: https://docs.docker.com/machine/overview/
I installed Docker for Mac.
> docker --version
Docker version 1.12.1, build 6f9534c
This post is duplicated with Default docker machine on Mac.
Docker 1.12 and onward no longer uses docker-machine to run containers. Instead it uses a native docker engine for mac/windows.

Docker Swarm Linking

I want to create a Docker Swarm Cluster running an elastic search instance, a MongoDB instance and a grails app, each on a separate machine. I'm using Docker Machine to set up my Docker Swarm Cluster
swarm-01:
mongodb
mongodb_ambassador
swarm-02:
elasticsearch
elasticsearch_ambassador
swarm-03:
mongodb_ambassador
elasticsearch_ambassador
grails
The last step of my setup, running the actual grails app, using the following command:
docker run -p 8080:8080 -d --name grails-master --volumes-from maven --link mongo:mongo-master --link es:es-master my-grails-image
fails with error:
Error response from daemon: Unable to find a node fulfilling all
dependencies: --volumes-from=maven --link=mongo:mongo-master
--link=es:es-master
The ambassador containers and the maven data container are all running on the same node.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
74677dad09a7 svendowideit/ambassador "/bin/sh -c 'env | gr" 18 minutes ago Up 18 minutes 9200/tcp, 9300/tcp swarm-03/es
98b38c4fc575 svendowideit/ambassador "/bin/sh -c 'env | gr" 18 minutes ago Up 18 minutes 27107/tcp swarm-03/mongo
7d45fb82eacc debian:jessie "/bin/bash" 20 minutes ago swarm-03/maven
I'm not able to get the Grails app running on the Swarm cluster; any advice would be appreciated. Running all containers on a single machine works, so I guess I'm making a mistake linking the mongo and es instances to the grails app.
Btw I'm using latest Docker Toolbox installation on OS X.
"linking" is deprecated in docker. Don't use it. It's complicated and not flexible enough.
Just create an overlay network for swarm mode.
docker network create -d overlay mynetwork
In swarm mode (even in single container mode), just add every service who should communicate with another service to the same network.
docker service create --network mynetwork --name mymongodb ...
Other services in the same network can reach your mongodb service just over the hostname mymongodb. That's all. Docker swarm mode has battery included.

Resources