I’m quite new in docker world.
I have a local virtulbox setup:
vm1=swarm manager (mysql,visualizer) IP: 192.168.99.100
vm2= wordpress service IP: 192.168.99.101
I can reach the application on both IP’s 100/101. But I would like to also use the localhost in order to port forward localhost to NET since 192.168.99.0 subnet is HOST only.
In VBOX I have portforwarding set like this for the NAT interface on the machine where apache runs:
HOST PORT 8888 / GUEST PORT 8888
Currently the YAML looks like this:
version: '3.4'
services:
wordpress:
image: wordpress
depends_on:
- mysql
- wordpress
deploy:
placement:
constraints: [node.labels.application==true]
mode: replicated
replicas: 1
update_config:
parallelism: 1
delay: 10s
restart_policy:
condition: on-failure
ports:
- "80:80"
environment:
WORDPRESS_DB_PASSWORD: "12345"
networks:
- wordpress_net
mysql:
image: mysql:latest
volumes:
- "/mnt/sda1/var/lib/docker/volumes/mysql_data/_data:/var/lib/mysql"
deploy:
placement:
constraints: [node.role == manager]
environment:
MYSQL_ROOT_PASSWORD: "12345"
networks:
- wordpress_net
visualizer:
image: dockersamples/visualizer:stable
ports:
- "8080:8080"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
deploy:
placement:
constraints: [node.role == manager]
networks:
- wordpress_net
networks:
wordpress_net:
How can I attach the eth0 interface to container. So both the swarm network and the NAT-ed network will be reachable ?
I was trying something like this but without success:
services:
wordpress:
image: wordpress
depends_on:
- mysql
- wordpress
deploy:
placement:
constraints: [node.labels.application==true]
mode: replicated
replicas: 1
update_config:
parallelism: 1
delay: 10s
restart_policy:
condition: on-failure
ports:
- target: 80
published: 80
protocol: tcp
mode: ingress
- target: 80
published: 8888
protocol: tcp
mode: host
environment:
WORDPRESS_DB_PASSWORD: "12345"
networks:
- wordpress_net
Thanks !
Related
So i have deploy my stack application and everything is working as expected. Three container replicas running. Now i access phpmyadmin and try to login to the mysql but i got the error: mysqli::real_connect(): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution
Both the phpmyadmin and mysql container are on the same network.
version: "3.9"
service:
db:
image: mysql
#container_name: mysql_db
command: --default-authentication-plugin=mysql_native_password
restart: always
secrets:
- mysql_root_password
- mysql_database
- mysql_user
- mysql_password
environment:
MYSQL_ROOT_PASSWORD_FILE: /run/secrets/mysql_root_password
MYSQL_DATABASE_FILE: /run/secrets/mysql_database
MYSQL_USER_FILE: /run/secrets/mysql_user
MYSQL_PASSWORD_FILE: /run/secrets/mysql_password
ports:
- "9906:3306"
networks:
- back-tier
volumes:
- alpine-db_backup:/var/lib/mysql
- alpine-mysql_logs:/var/log/mysql
- alpine-mysql_cnf:/etc/mysql
deploy:
replicas: 3
placement:
constraints: [node.role == manager]
resources:
reservations:
memory: 128M
limits:
memory: 256M
restart_policy:
condition: on-failure
delay: 30s
max_attempts: 10
window: 60s
update_config:
parallelism: 1
delay: 10s
max_failure_ratio: 0.3
phpmyadmin:
image: phpmyadmin
#container_name: phpmyadmin
ports:
- 8080:80
environment:
PMA_HOST: db
PMA_PORT: 3306
PMA_ARBITRARY: 1
depends_on:
- db
networks:
- back-tier
- front-tier
deploy:
replicas: 2
resources:
limits:
cpus: '0.50'
memory: 50M
reservations:
cpus: '0.25'
memory: 20M
restart_policy:
condition: on-failure
delay: 30s
max_attempts: 10
networks:
front-tier:
driver: overlay
back-tier:
driver: overlay
For containers on the same network, to get another service's name resolved, you should use its name without the stack name as prefix. So, your PMA_HOST should be db, not titanfxbmp_db.
version: "3.9"
services:
db:
image: mysql
...
phpmyadmin:
image: phpmyadmin
...
environment:
PMA_HOST: db
PMA_PORT: 3306
Trying to get the docker-compose.yml working from the getting started tutorials
I have a docker image that I'm using docker compose to start a container with. What's confusing is that after I start the container and I make edits to the database and close the container down (docker-compose down), the database changes are persistent (which is what I want)
**version: "3.8"
services:
db:
image: mysql:latest
volumes:
- type: volume
source: dbmysql
target: /var/lib/mysql
networks:
- webappnet
environment:
MYSQL_ROOT_PASSWORD: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
MYSQL_DATABASE: wordpress
deploy:
replicas: 1
update_config:
delay: 5s
parallelism: 1
restart_policy:
condition: on-failure
placement:
constraints: [node.hostname == master]
web:
depends_on:
- db
image: wordpress:latest
volumes:
- type: volume
source: dbweb
target: /var/wwwh/html
networks:
- webappnet
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
deploy:
replicas: 1
update_config:
delay: 10s
restart_policy:
condition: on-failure
placement:
constraints: [node.hostname == slave1]
volumes:
dbmysql:
dbweb:
networks:
webappnet:
driver: overlay
name: webappname**
Getting this error:
Additional property web is not allowed
What have I typed in wrong?
Thanks.
**I'm trying to use Traefik to load-balance my web apps via docker swarm.
I have installed sample application like joomla in swarm mode behind traefik. Joomla works fine when the application is deployed on the same node as traefik (ie, manager), and I can access it through the browser by hitting the manager's node IP. But, if the service gets deployed on the worker node with no container in the manager node, while the service is up and running without any issue, but I am not able to see anything on the browser (hitting the manager or worker IP)
My traefik.toml file:
defaultEntryPoints = ["http"]
loglevel = "INFO"
sendAnonymousUsage = true
[docker]
endpoint = "unix:///var/run/docker.sock"
exposedByDefault = false
[api]
dashboard = true
entrypoint = "dashboard"
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.dashboard]
address = ":8080"
--------------------------------
My traefik.yml file:
version: '3'
services:
traefik:
image: traefik:v1.7 # The official Traefik docker image
restart: always
ports:
- 80:80 # The HTTP port
- 9090:8080 # The Web UI (enabled by --api)
labels:
- traefik.frontend.rule=Host:traefik.dpaas1.pune.cdac.in
- traefik.port=8080
- traefik.enable=true
volumes:
- /var/run/docker.sock:/var/run/docker.sock # So that Traefik can listen to the Docker events
- ${PWD}/traefik.toml:/etc/traefik/traefik.toml
deploy:
mode: replicated
replicas: 1
restart_policy:
condition: on-failure
max_attempts: 3
placement:
constraints: [node.role == manager]
update_config:
delay: 2s
networks:
- net
networks:
net:
external: true
My joomla.yml file:
version: '3'
services:
joomla:
image: joomla
restart: always
links:
- joomladb:mysql
volumes:
- joomla1-www:/var/www/html
deploy:
mode: replicated
replicas: 3
restart_policy:
condition: on-failure
max_attempts: 3
placement:
constraints: [node.role == manager]
update_config:
delay: 2s
labels:
- traefik.frontend.rule=Host:joomla1.dpaas1.pune.cdac.in
- traefik.port=80
- traefik.enable=true
- traefik.backend.loadbalancer.sticky=true
environment:
JOOMLA_DB_HOST: 10.208.26.162
JOOMLA_DB_PASSWORD: root
tty: true
networks:
- net
networks:
net:
external: true
volumes:
joomla1-www:
_______________________
```_____________ **
My traefik Dashboard:
[![Traefik logs and dashboard][1]][1]
[1]: https://i.stack.imgur.com/tcoGu.png
I just completed the docker documentation and created two instances on aws (http://13.127.150.218, http://13.235.134.73). The first one is manager and the second one is the worker. Following is the composed file I used to deploy
version: "3"
services:
web:
# replace username/repo:tag with your name and image details
image: username/repo:tag
deploy:
replicas: 5
restart_policy:
condition: on-failure
resources:
limits:
cpus: "0.1"
memory: 50M
ports:
- "80:80"
networks:
- webnet
visualizer:
image: dockersamples/visualizer:stable
ports:
- "8080:8080"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
deploy:
placement:
constraints: [node.role == manager]
networks:
- webnet
redis:
image: redis
ports:
- "6379:6379"
volumes:
- "/home/docker/data:/data"
deploy:
placement:
constraints: [node.role == manager]
command: redis-server --appendonly yes
networks:
- webnet
networks:
webnet:
Here the redis service has the constraint that restricts it to run only on manager node. Now my question is how the web service on worker instance is supposed to use the redis service.
You need to use the hostname parameter in all container, so you can use this value to access services from worker or to access from worker the services on manager.
version: "3"
services:
web:
# replace username/repo:tag with your name and image details
image: username/repo:tag
hostname: "web"
deploy:
replicas: 5
restart_policy:
condition: on-failure
resources:
limits:
cpus: "0.1"
memory: 50M
ports:
- "80:80"
networks:
- webnet
visualizer:
image: dockersamples/visualizer:stable
hostname: "visualizer"
ports:
- "8080:8080"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
deploy:
placement:
constraints: [node.role == manager]
networks:
- webnet
redis:
image: redis
hostname: "redis"
ports:
- "6379:6379"
volumes:
- "/home/docker/data:/data"
deploy:
placement:
constraints: [node.role == manager]
command: redis-server --appendonly yes
networks:
- webnet
networks:
webnet:
In addictional if you use the portainer instead of visualizer you can control you SWARM stack with more options:
https://hub.docker.com/r/portainer/portainer
BR,
Carlos
Consider the stack file as per the below example -
Regardless of where it is placed manager|worker all the services in the stack file being on the same network can use the embedded DNS functionality which helps to resolve each service by the service name defined.
In this case the service web makes use of service redis by its service name.
Here is an example of the ping command able to resolve the service web from within the container associated with the redis service -
Read more about the Swarm Native Service Discovery to understand this.
I've just used the example from this documentation(https://media.readthedocs.org/pdf/portainer/1.19.1/portainer.pdf)
to configure the portainer's agent but keep receiving the error "Unable to proxy the request via the Docker socket". In this case the stack is displayed as "down".
Portainer works just fine without the agent and mounting docker.sock.
This is the docker-compose fragment
agent:
image: portainer/agent
environment:
AGENT_CLUSTER_ADDR: tasks.agent
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /var/lib/docker/volumes:/var/lib/docker/volumes
networks:
- agent_network
deploy:
mode: global
placement:
constraints: [node.platform.os == linux]
portainer:
image: portainer/portainer
command: -H tcp://tasks.agent:9001 --tlsskipverify
ports:
- target: 9000
published: 9000
protocol: tcp
mode: ingress
volumes:
- portainer_data:/data
networks:
- agent_network
deploy:
mode: replicated
replicas: 1
placement:
constraints: [node.role == manager]