Docker Community Forums

Share and learn in the Docker community.

Docker-compose with swarm n variables DB_PORT_* DB_ENV_* failed to pass to script

docker

(knnleow) #1

this is an extract on my script file used in dockerfile and docker-compose.yml
(refer to full source at https://github.com/knnleow/wordpress-nginx-selfsignedcert)

$ cat Dockerfile
:
# Command to run
ENTRYPOINT ["/script.d/run-all.sh"]
CMD [""]

$ cat run-once.sh
:
# Env. Variables
# ==============
SERVER_NAME=$SERVER_NAME
DB_HOST=$DB_PORT_3306_TCP_ADDR
DB_HOSTNAME=$DB_PORT_3306_TCP_ADDR
DB_DATABASE=$DB_ENV_MYSQL_DATABASE
DB_USER=$DB_ENV_MYSQL_USER
DB_PASSWORD=$DB_ENV_MYSQL_PASSWORD
:
sed -i -e ‘s/database_name_here/$DB_DATABASE/g’ /var/www/html/wp-config.php
sed -i -e ‘s/username_here/$DB_USER/g’ /var/www/html/wp-config.php
sed -i -e ‘s/password_here/$DB_PASSWORD/g’ /var/www/html/wp-config.php
sed -i -e ‘s/localhost/$DB_HOST/g’ /var/www/html/wp-config.php
:

$ cat run-all.sh
:
# Initialize first run
if [[ -e /script.d/.run-once ]]; then
/script.d/run-once.sh
fi
:

docker-compose tested and working on a standalone docker.
but when i port to swarm, the custom wordpress-nginx-selfsignedcert and mysql 5.7 containers created successfully, but error connection to the database when try access the Wordpress URL.
i have to go into the wordpress container to edit and update the /var/www/html/wp-config.php file with the correct definition.

the VARIABLES do not get passed into my script once use swarm

Queston:
Are these VARIABLE still works for swarm? if not what i did wrong?
1. DB_HOST=$DB_PORT_3306_TCP_ADDR
2. DB_HOSTNAME=$DB_PORT_3306_TCP_ADDR
3. DB_DATABASE=$DB_ENV_MYSQL_DATABASE
4. DB_USER=$DB_ENV_MYSQL_USER
5. DB_PASSWORD=$DB_ENV_MYSQL_PASSWORD

regards,
kuenn


(knnleow) #2

solved. syntax changes from version 1 to version 2