I am trying to create a php: apache service with Docker Swarm. I have 3 nodes, manager, node1, node2. I have created the Dockerfile file:
FROM php:apache
COPY html/ /var/www/html/
And the docker-compose.yml file:
version: "3"
networks:
network1:
services:
php:
build:
context: ./
dockerfile: Dockerfile
image: "php:apache"
ports:
- "80:80"
deploy:
mode: global
networks:
- network1
When I run
docker stack deploy --compose-file docker-compose.yml s2
The service is created correctly (3 REPLICAS)
[vagrant@manager php]$ docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
ojoz9i15gud4 s2_php global 3/3 php:apache *:80->80/tcp
but I cant acces to php content because I get this:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access this resource.</p>
<hr>
<address>Apache/2.4.38 (Debian) Server at 192.168.100.100 Port 80</address>
</body></html>
So I added the volume to docker-compose.yml
version: "3"
networks:
network1:
services:
php:
build:
context: ./
dockerfile: Dockerfile
image: "php:apache"
ports:
- "80:80"
volumes:
- ./html/:/var/www/html/
deploy:
mode: global
networks:
- network1
But now when I create the service is only in manager node, 1 REPLICA:
[vagrant@manager php]$ docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
5e9ts14itaow s2_php global 1/1 php:apache *:80->80/tcp
Can someone explain to me why this happens?