Why can't application can't been accessed which deploy by docker stack in a docker swarm cluster?

In a docker swarm cluster, there is one master and two workers.

Make a yaml file on master host:

stack.yml

version: '3.1'

services:

  wordpress:
    image: wordpress
    restart: always
    ports:
      - 8080:80
    environment:
      WORDPRESS_DB_PASSWORD: example

  mysql:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: example

Deploy the stack by docker stack

$ docker stack deploy -c stack.yml wordpress

Check on master host:

$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
f24d160ef788        wordpress:latest    "docker-entrypoint.s…"   19 seconds ago      Up 13 seconds       80/tcp              wordpress_wordpress.1.5rilktpp43xtv1avtmp0uuh0u

# This is I downloaded the images myself:
$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
wordpress           latest              c649c99a766e        12 hours ago        408MB
mysql               5.7                 0d16d0a97dd1        2 weeks ago         372MB

$ docker service ls
ID                  NAME                  MODE                REPLICAS            IMAGE               PORTS
ra3wfcq8owmb        wordpress_mysql       replicated          1/1                 mysql:5.7
hosko1vl55wq        wordpress_wordpress   replicated          1/1                 wordpress:latest    *:8080->80/tcp

Check on worker1 host:

$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
f91c127d6166        wordpress:latest    "docker-entrypoint.s…"   12 seconds ago      Up 10 seconds       80/tcp              wordpress_wordpress.1.98fkpvprkdjwkdik2hieqcg7g

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
wordpress           <none>              c649c99a766e        12 hours ago        408MB

Check on worker2 host:

$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS              PORTS               NAMES
6465e16ee5b4        0d16d0a97dd1        "docker-entrypoint.s…"   About a minute ago   Up About a minute   3306/tcp            wordpress_mysql.1.xhrfekxylgycyp0qf6ca7h9ok

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
wordpress           <none>              c649c99a766e        12 hours ago        408MB

Deploy it by docker-compose

$ docker-compose -f stack.yml up

Works very well.


Questions

  • Why deployed by docker stack ... didn’t pull the images on all the cluster hosts?
  • Why it can’t been accessed by docker-compose way can?
  • Is docker-compose way also deploy the containers on the whole swarm cluster?