I am trying to deploy my PHP app in the docker container. Using docker secret I want to store the password of the MySQL database. First I created a docker secret mysql_password. My docker-compose file is -
version: '3.9' services: php: image: 'php:7.2-fpm' build: context: ./docker dockerfile: php.Dockerfile volumes: - './app:/var/www/html' environment: MYSQL_PASSWORD_FILE: /run/secrets/mysql_password secrets: - mysql_password nginx: image: nginx:latest ports: - '80:80' links: - 'php' volumes: - './app:/var/www/html' - './config/nginx:/etc/nginx/conf.d' secrets: mysql_password: external: true
- When I try to access the secret ‘mysql_password’ is is not returning anything. And if I try environment element ‘MYSQL_PASSWORD_FILE’, it is giving me the path of secret that is ‘/run/secrets/mysql_password’.
- To access environment variable in PHP I have used .$_ENV[“mysql_password”]