I am trying to generate the random password using bash script and then pass it to the docker-compose file to replace the value of WORDPRESS_DB_PASSWORD
in docker-compose file. It is generating the random password but I am not able to substitute the value in docker-compose.
Bash script
#!bin/bash
password= tr -dc 'a-zA-Z0-9' < /dev/urandom | head -c10
echo $password
INPUT=dockercompose.yaml
sed -i -e 's/\(^WORDPRESS_DB_PASSWORD=\).*/\1$password/' $INPUT
dockercompose.yaml
version: '3.1'
services:
wordpress:
image: wordpress
restart: always
ports:
- 8080:80
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: exampleuser
WORDPRESS_DB_PASSWORD: examplepass
WORDPRESS_DB_NAME: exampledb
volumes:
- wordpress:/var/www/html
db:
image: mysql:5.7
restart: always
environment:
MYSQL_DATABASE: exampledb
MYSQL_USER: exampleuser
MYSQL_PASSWORD: examplepass
MYSQL_RANDOM_ROOT_PASSWORD: '1'
volumes:
- db:/var/lib/mysql
volumes:
wordpress:
db: