I deployed my docker stack:
⇒ docker stack deploy -c docker-compose.yml my_stack
Creating network my_stack_network
Creating service my_stack_redis
Creating service my_stack_wsgi
Creating service my_stack_nodejs
Creating service my_stack_nginx
Creating service my_stack_haproxy
Creating service my_stack_postgres
But when I do docker container ls, it only shows three containers:
~|⇒ docker container ls | grep my_stack
212720bfafc3 postgres:11 "docker-entrypoint.s…" 4 minutes ago Up 3 minutes 5432/tcp my_stack_postgres.1.9nx7jb21whi61aboe9hmet6m2
3132dd980589 isiq/nginx-brotli:1.21.0 "/docker-entrypoint.…" 4 minutes ago Up 4 minutes 80/tcp my_stack_nginx.1.isl2c78z6w5ptizurm3a4cnte
62ef3c76fb9e redis:6.2.4 "docker-entrypoint.s…" 4 minutes ago Up 4 minutes 6379/tcp my_stack_redis.1.xnisrd1i6hod6jkm64623cpzj
But docker stack ps lists all of them as Running:
~|⇒ docker stack ps --no-trunc my_stack
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
1fqwlgblhi5q0cdl5cy75ucli my_stack_haproxy.1 haproxy:2.3.9#sha256:f63aabf39efcd277b04a503d38e59e80224a0c11f47b2568b13b0092698c5a3a Running New 2 minutes ago
isl2c78z6w5ptizurm3a4cnte my_stack_nginx.1 isiq/nginx-brotli:1.21.0#sha256:436cbc0d8cd051e7bdb197d7915fe90fa5a1bdadea6d02272ba117fccf30c936 tadoba Running Running 2 minutes ago
1myvtgl11qqw2xa9cv79uikcs my_stack_nodejs.1 nodejs:my_stack Running New 2 minutes ago
9nx7jb21whi61aboe9hmet6m2 my_stack_postgres.1 postgres:11#sha256:5d2aa4a7b5f9bdadeddcf87cf7f90a176737a02a30d917de4ab2e6a329bd2d45 tadoba Running Running 2 minutes ago
xnisrd1i6hod6jkm64623cpzj my_stack_redis.1 redis:6.2.4#sha256:6bc98f513258e0c17bd150a7a26f38a8ce3e7d584f0c451cf31df70d461a200a tadoba Running Running 2 minutes ago
mzmmb7a3bxjpfkfa3ea5o5w85 my_stack_wsgi.1 wsgi:my_stack Running New 2 minutes ago
Checking logs of containers not listed in docker container ls gives No such container error:
~|⇒ docker logs -f 1myvtgl11qqw2xa9cv79uikcs
Error: No such container: 1myvtgl11qqw2xa9cv79uikcs
~|⇒ docker logs -f mzmmb7a3bxjpfkfa3ea5o5w85
Error: No such container: mzmmb7a3bxjpfkfa3ea5o5w85
~|⇒ docker logs -f 1fqwlgblhi5q0cdl5cy75ucli
Error: No such container: 1fqwlgblhi5q0cdl5cy75ucli
What could be the reason? How can I debug this?
Update
It seems that services without dependencies are able to join the network. But services with dependencies on other services are not able to. I am unable to figure out the reason. Here is the gist with output of docker inspect network's output.
PS
I run watch 'docker container ls | grep my_app' in another terminal before running docker stack deploy .... But those three containers never appear in the watch list. Rest of three do appear.
I am running all nodes on the same remote machine connected through ssh. This is the output of docker node ls:
~|⇒ docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
z9hovq8ry6qont3m2rbn6upy4 * tadoba Ready Active Leader 20.10.11
Here is my docker compose file for reference:
version: "3.8"
services:
postgres:
image: postgres:11
volumes:
- my_app_postgres_volume:/var/lib/postgresql/data
- type: tmpfs
target: /dev/shm
tmpfs:
size: 536870912 # 512MB
environment:
POSTGRES_DB: my_app_db
POSTGRES_USER: my_app
POSTGRES_PASSWORD: my_app123
networks:
- my_app_network
redis:
image: redis:6.2.4
volumes:
- my_app_redis_volume:/data
networks:
- my_app_network
wsgi:
image: wsgi:my_app3_stats
volumes:
- /my_app/frontend/static/
- ./wsgi/my_app:/my_app
- /my_app/frontend/clientApp/node_modules
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
depends_on:
- postgres
- redis
ports:
- 9090
environment:
C_FORCE_ROOT: 'true'
SERVICE_PORTS: 9090
networks:
- my_app_network
deploy:
replicas: 1
update_config:
parallelism: 1
delay: 10s
restart_policy:
condition: on-failure
max_attempts: 3
window: 120s
nodejs:
image: nodejs:my_app3_stats
volumes:
- ./nodejs/frontend:/frontend
- /frontend/node_modules
depends_on:
- wsgi
ports:
- 9998:9999
environment:
BACKEND_API_URL: http://aa.bb.cc.dd:9764/api/
networks:
- my_app_network
nginx:
image: isiq/nginx-brotli:1.21.0
volumes:
- ./nginx:/etc/nginx/conf.d:ro
- ./wsgi/my_app:/my_app:ro
- my_app_nginx_volume:/var/log/nginx/
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
networks:
- my_app_network
haproxy:
image: haproxy:2.3.9
volumes:
- ./haproxy:/usr/local/etc/haproxy/:ro
- /var/run/docker.sock:/var/run/docker.sock
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
depends_on:
- wsgi
- nodejs
- nginx
ports:
- 9764:80
networks:
- my_app_network
deploy:
placement:
constraints: [node.role == manager]
volumes:
my_app_postgres_volume:
my_app_redis_volume:
my_app_nginx_volume:
my_app_pgadmin_volume:
networks:
my_app_network:
driver: overlay
Output of docker service ps <service-name> for services not listed under tadoba node:
~/my_app|master-py3⚡
⇒ docker service ps my_app_nodejs
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
i04jpykp9ign my_app_nodejs.1 nodejs:bodhitree3_stats Running New about a minute ago
~/my_app|master-py3⚡
⇒ docker service ps my_app_haproxy
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
of4fcsxuq24c my_app_haproxy.1 haproxy:2.3.9 Running New about a minute ago
~/my_app|master-py3⚡
⇒ docker service ps my_app_wsgi
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
yt9nuhule39z my_app_wsgi.1 wsgi:bodhitree3_stats Running New 2 minutes ago
Firstly all of the services are running which is good. But docker container ls isn't cluster-aware i.e. it is showing the current containers running on this node. From the output docker stack ps --no-trunc my_stack I can see that there is another node labeled tadoba. So if you can log in to the other node you can see the running containers.
You can list the nodes on your cluster by running docker node ls.
If you want you can set up your docker contexts so you can change your docker context which will remove the need to log in and log out of the nodes. You can find more info here.
Related
After I carry out docker-compose up, it starts the containers.
when I do docker ps I get the below, which tells me that the containers are running. However when I do docker network inspect bridge the result shows me that there are no containers part of the docker0 bridge.
When I then carry out docker run meanchat_myserver it actually does show up on docker0 and I am also getting the data that the server is running on port 3000.
Which I don't get by using docker-compose.
What am I doing wrong here?
I am reading that when I use docker0 I can only refer to IP's to connect to other containers and not the name. Can I assume the ip's don't change on the containers and that this works without issue on deploying the app in production?
02cf08b1c3da d57f06ba9c68 "npm start" 33 minutes ago Up 33 minutes 4200/tcp meanchat_client_1
e257063c9e21 meanchat_myserver "npm start" 33 minutes ago Up 33 minutes 3000/tcp meanchat_myserver_1
02441c2e43f5 e114a298eabd "npm start" About an ago Up 33 minutes 0.0.0.0:80->80/tcp meanchat_nginx_1
88d9841d2553 mongo "docker-entrypoint..." 3 hours ago Up 3 hours 27017/tcp meanchat_mongo_1
compose
version: '3'
services:
# Build the container using the client Dockerfile
client:
build: ./
# This line maps the contents of the client folder into the container.
volumes:
- ./:/usr/src/app
myserver:
build: ./express-server
volumes:
- ./:/usr/src/app
depends_on:
- mongo
nginx:
build: ./nginx
# Map Nginx port 80 to the local machine's port 80
ports:
- "80:80"
# Link the client container so that Nginx will have access to it
mongo:
environment:
- AUTH=yes
- MONGO_INITDB_ROOT_USERNAME=superAdmin
- MONGO_INITDB_ROOT_PASSWORD=admin123
- MONGO_INITDB_DATABASE=d0c4ae452a5c
image: mongo
volumes:
- /var/mongodata/data:/data/db
By default Compose sets up a single network for your app.
For more detail, refer this link.
This means containers with compose won't be located in default bridge network by default.
You can check which network the containers with compose are using with the command.
docker inspect $container_name -f "{{.NetworkSettings.Networks}}"
However, If you want containers to be in default bridge network, you can use network_mode.
services:
service_name:
# other options....
network_mode: bridge
I am trying to deploy my working docker-compose set up to a docker-swarm, everything seems ok, except that the only service that got replicate and generate a running container is the redis one, the 3 others got stuck and never generate any running container, they don't even download their respective images.
I can't find any debug feature, all the logs are empty, I'm completely helpless.
Let me show you the current state of my installation.
docker node ls print =>
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
oapl4et92vjp6mv67h2vw8boq boot2docker Ready Active
x2fal9iwj6aqt1vgobyp1smv1 * manager1 Ready Active Leader
lmtuojednaiqmfmm2izl7npf0 worker1 Ready Active
The docker compose =>
version: '3'
services:
mongo:
image: mongo
container_name: mongo
restart: always
volumes:
- /data/db:/data/db
deploy:
placement:
constraints: [node.role == manager]
ports:
- "27017:27017"
redis:
image: redis
container_name: redis
restart: always
bnbkeeper:
image: registry.example.tld/keepers:0.10
container_name: bnbkeeper
deploy:
replicas: 5
resources:
limits:
cpus: "0.1"
memory: 50M
restart_policy:
condition: on-failure
depends_on:
- mongo
- redis
ports:
- "8080:8080"
links:
- mongo
- redis
environment:
- REDIS_HOST=redis
- MONGO_HOST=mongo
bnbkeeper-ws:
image: registry.example.tld/keepers:0.10
container_name: bnbkeeper-ws
restart: unless-stopped
depends_on:
- mongo
- redis
ports:
- "3800:3800"
links:
- mongo
- redis
environment:
- REDIS_HOST=redis
command: npm run start:subscription
The current state of my services
ID NAME MODE REPLICAS IMAGE PORTS
tbwfswsxx23f stack_bnbkeeper replicated 0/5 registry.example.tld/keepers:0.10
khrqtx28qoia stack_bnbkeeper-ws replicated 0/1 registry.example.tld/keepers:0.10
lipa8nvncpxb stack_mongo replicated 0/1 mongo:latest
xtz2411htcg7 stack_redis replicated 1/1 redis:latest
My redis successful service (docker service ps stack_redis)
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
cqv0njcgsw6f stack_redis.1 redis:latest worker1 Running Running 25 minutes ago
my mongo unsuccessful service (docker service ps stack_mongo)
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
yipokxxiftqq stack_mongo.1 mongo:latest Running New 25 minutes ago
I'm completely new to docker swarm, and probably made a silly mistake here, but I couldn't find much documentation on how to setup such a simple stack.
To monitor, try this:
journalctl -f -n10
Then run the docker stack deploy command in a separate session and see what it shows
try removing port publish and add --endpoint-mode dnsrr to your service.
I'm trying to dockerize a Python application, for which I've been following this tutorial. The tutorial is from April 2015 and still uses Docker Machine, which, judging from this answer, is no longer necessary to run Docker containers locally on Windows.
I got it working with Docker Machine before, and was able to see the web app and interact with it. But now I'm trying to get this working without Docker Machine, with Docker version 17.06.0-ce, build 02c1d87, on Windows 10.
Here's the docker-compose.yml:
web:
restart: always
build: ./web
expose:
- "8000"
links:
- postgres:postgres
volumes:
- /usr/src/app/static
env_file: .env
command: /usr/local/bin/gunicorn -w 2 -b :8000 app:app
nginx:
restart: always
build: ./nginx/
ports:
- "80:80"
volumes:
- /www/static
volumes_from:
- web
links:
- web:web
data:
image: postgres:latest
volumes:
- /var/lib/postgresql
command: "true"
postgres:
restart: always
image: postgres:latest
volumes_from:
- data
ports:
- "5432:5432"
I started the containers:
$ docker-compose up -d
Creating polly_data_1 ...
Creating polly_data_1 ... done
Creating polly_postgres_1 ...
Creating polly_postgres_1 ... done
Creating polly_web_1 ...
Creating polly_web_1 ... done
Creating polly_nginx_1 ...
Creating polly_nginx_1 ... done
Then, when I run docker ps, it shows the following three containers running:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9b2c1048f3a5 polly_nginx "/usr/sbin/nginx" 4 seconds ago Up 3 seconds 0.0.0.0:80->80/tcp polly_nginx_1
d561ac5b901a polly_web "/usr/local/bin/gu..." 5 seconds ago Up 4 seconds 8000/tcp polly_web_1
ecb029d6ec3a postgres:latest "docker-entrypoint..." 7 seconds ago Up 5 seconds 0.0.0.0:5432->5432/tcp polly_postgres_1
(At this point, navigating to http://localhost:8000/ in Chrome already yields ERR_CONNECTION_REFUSED.)
I then ran the script to set up the database, as per the tutorial (extra //s because I'm using Git Bash on Windows 10):
$ docker-compose run web ///usr/local/bin/python create_db.py
Starting polly_data_1 ...
Starting polly_data_1 ... done
Starting polly_postgres_1 ... done
Now when I run docker ps, it shows the following four containers running:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a129c12f5982 polly_web "//usr/local/bin/p..." 5 seconds ago Up Less than a second 8000/tcp polly_web_run_1
9b2c1048f3a5 polly_nginx "/usr/sbin/nginx" 16 seconds ago Up 15 seconds 0.0.0.0:80->80/tcp polly_nginx_1
d561ac5b901a polly_web "/usr/local/bin/gu..." 17 seconds ago Up 16 seconds 8000/tcp polly_web_1
ecb029d6ec3a postgres:latest "docker-entrypoint..." 19 seconds ago Up 17 seconds 0.0.0.0:5432->5432/tcp polly_postgres_1
And localhost:8000 is still refusing to connect. The web container exposes port 8000, so I don't get why I can't connect to it.
How can I get this working so I can access the web app in the web container locally?
Just change:
expose:
- "8000"
By
ports:
- "8000:8000"
Btw http://localhost:80 is not working?
Regards
Turns out, as suggested by Carlos and 200_OK as part of their answers and comments, it was working as intended - it was running at port 80, not 8000.
Web exposes port 8000 internally inside the container. But that port is not mapped to your host machine port.
I think the problem is in your command. The option is -p, not -b.
web:
restart: always
build: ./web
expose:
- "8000"
links:
- postgres:postgres
volumes:
- /usr/src/app/static
env_file: .env
command: /usr/local/bin/gunicorn -w 2 -p :8000 app:app
I'm trying to execute the tutorial from the official documentation. It works fine except with Services.
When I start 5 instances of the container (with docker stack command), the containers are not starting and I get this error:
"failed to allocate gateway"
$ docker stack ps getstartedlab
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
imb6vgifjvq7 getstartedlab_web.1 seb/docker-whale:1.1 ns3553081.ip-XXX-YYY-ZZZ.eu Ready Rejected 4 seconds ago "failed to allocate gateway (1…"
ulm1tqdhzikd \_ getstartedlab_web.1 seb/docker-whale:1.1 ns3553081.ip-XXX-YYY-ZZZ.eu Shutdown Rejected 9 seconds ago "failed to allocate gateway (1…"
...
The docker-compose.yml contains
version: "3"
services:
web:
image: seb/docker-whale:1.1
deploy:
replicas: 5
resources:
limits:
cpus: "0.1"
memory: 50M
restart_policy:
condition: on-failure
ports:
- "80:80"
networks:
- webnet
networks:
webnet:
to start containers I'm using the command:
$ docker stack deploy -c docker-compose.yml getstartedlab
I can start without any issue one instance of the container with the command:
$ docker run -p 80:80 seb/docker-whale:1.1
Any idea why it's not working? How can I get more details on the error?
Thanks for your help.
Answer from a beginner: Same here (version 1.13.1), the message vanished when I changed ports "80:80" to "8080:80". Port 80 was used by the host of the docker machine.
I am new to Docker and I am following the 'Getting Started' documentation at the Docker site.
I am trying to run 3 containers on a VM.
OS: Centos 7.3
Docker: 17.03.1-ce
I followed the first part and could get hello-world running on a container inside the VM.
Then I moved on to the Docker compose example.
I have the following directory structure:
home
|
- docker-compose.yml
|
- docker-test
|
- app.py
- Dockerfile
- requirements.txt
The files under docker-test are from the python app example on the docker website.
With the docker-compose, I was attempting to run 3 containers of the hello-world example.
My docker-compose.yml:
version: "3"
services:
web:
image: hello-world
deploy:
replicas: 3
resources:
limits:
cpus: "0.1"
memory: 50M
restart_policy:
condition: on-failure
ports:
- "80:80"
networks:
- webnet
networks:
webnet:
Then I ran the following commands:
sudo docker swarm init
sudo docker stack deploy -c docker-compose.yml getstartedlab
sudo docker stack ps getstartedlab shows:
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
iytr4ptz3m8l getstartedlab_web.1 hello-world:latest <node1> Shutdown Complete 16 minutes ago
s5t41txo05ex getstartedlab_web.2 hello-world:latest <node2> Shutdown Complete 16 minutes ago
91iitdnc49fk getstartedlab_web.3 hello-world:latest <node3> Shutdown Complete 16 minutes ago
However,
sudo docker ps shows no containers and when I curl http://localhost:80, it can't connect.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
What am I missing?
Your docker-compose.yml file says that the web service should use the hello-world image, which just prints a message & exits when run, leading to all of the containers being stopped. Presumably, you meant to instead use the image created by building docker-test/; to do this, simply replace the image: hello-world line with build: docker-test.