Note: am new to docker/swarm.
I've created a WordPress/mysql containers in a docker swarm mode running on Azure as per https://docs.docker.com/compose/wordpress/.
The cluster was created as per https://docs.docker.com/docker-for-azure/
here is my dockerfile:
======================
version: '3.3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
db_data: {}
=======================
as per official documentation, I can publish ports using --published
flag, however, I need to know how to include that in Dockerfile.
Running apps You can now start creating containers and services.
$ docker run hello-world
You can run websites too. Ports exposed with --publish are automatically exposed through the platform load balancer:
$ docker service create --name nginx --publish published=80,target=80 nginx
Once up, find the DefaultDNSTarget output in either the AWS or Azure portals to access the site.
Using docker ps, I can see that it is listening on 0.0.0.0:8000->80, however, without a service, it will not automatically create an azure load balance rule to the container.
swarm-manager000000:~/compose$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8c94587acd97 wordpress:latest "docker-entrypoint.s…" 10 minutes ago Up 10 minutes 0.0.0.0:8000->80/tcp compose_wordpress_1
aff61e0022a8 mysql:5.7 "docker-entrypoint.s…" 10 minutes ago Up 10 minutes 3306/tcp, 33060/tcp compose_db_1
5d2fdb3d75c4 docker4x/l4controller-azure:18.09.2-ce-azure1 "loadbalancer run --…" 2 hours ago Up 2 hours editions_controller
d5f0a8a91f66 docker4x/meta-azure:18.09.2-ce-azure1 "metaserver -iaas_pr…" 2 hours ago Up 2 hours 10.0.0.4:9024->8080/tcp meta-azure
93c6571b6ee6 docker4x/guide-azure:18.09.2-ce-azure1 "/entry.sh" 2 hours ago Up 2 hours editions_guide
b6cad5676b10 docker4x/logger-azure:18.09.2-ce-azure1 "python /server.py" 2 hours ago Up 2 hours 0.0.0.0:514->514/udp editions_logger
d2a74fe21751 docker4x/agent-azure:18.09.2-ce-azure1 "supervisord --confi…" 2 hours ago Up 2 hours agent
swarm-manager000000:~/compose$
If, for example, I tried to create a service that is mapped to a new image i.e: nginx. this will immediately create an inbound rule in the Azure load balancer.
$ docker service create --name nginx --publish published=80,target=80 nginx
Please advise of how to map the service to the existing WordPress container, or how to update the Dockerfile to create the service and use --published
.
Thanks