Score:0

Switch from php7.2 to 7.4 and from alpine to ubuntu shell script/Dockerfile question

cn flag

This is in a Dockerfile with

FROM phusion/baseimage:hirsute

as foundation.

This part was working with php7.2 but we needed to switch to php7.4

The environment variable are contained in a .env file in the Format DB_USER='username'

or in the docker-compose.yml as environment as:

environment:
      - DB_USER=${DB_USER:-default} 
      - DB_PASS=password
      - DB_NAME=database

Original Part 1 of creation of dbconnect.php (Dockerfile)

RUN { \
         echo "<?php"; \
         echo "    \$db        = getenv('DB_DRIVER') ?: 'mysqli';"; \
         echo "    \$dbversion = getenv('DB_VERSION') ?: '8';"; \
         echo "    \$host      = getenv('DB_HOST') ?: 'db';"; \
         echo "    \$user      = getenv('DB_USER');"; \
         echo "    \$pass      = getenv('DB_PASS');"; \
         echo "    \$dbs       = getenv('DB_NAME') ?: 'database';"; \
         echo "    \$client_charset = 'utf8mb4';"; \ 
     } > /var/www/html/db/dbconnect.php

Original Part 1 of creation of dbconnect.php Produces in the current running container:

<?php
    $db        = getenv('DB_DRIVER') ?: 'mysqli';
    $dbversion = getenv('DB_VERSION') ?: '8';
    $host      = getenv('DB_HOST') ?: 'db';
    $user      = getenv('DB_USER');
    $pass      = getenv('DB_PASS');
    $dbs       = getenv('DB_NAME') ?: 'database';
    $client_charset = 'utf8mb4';

So password and user have no default, but anyhow it it just echos without any usage of the variables.

I played around and produced test variants.

Following Variants Part2: all not working:

 RUN { echo     "<?php"; \
       echo "\$pass=";\
       echo "${tikipass}" ; \
       echo "getenv ${DB_USER}" ; \
       echo "$DB_USER" ; \
       echo "getenv('DB_USER')"; \
       echo "hallo"; \
       echo "Count = $DB_USER.\n"; \
     } > /var/www/html/db/dbconnect.php

Output of Variant Part 2 of creation of dbconnect.php Produces in the running container:

<?php
$pass=
getenv 

getenv('DB_USER')
hallo
Count = .

So all variant i could think of just dont catch the variable content

The resulting dbconnect.php should be in the following format:

<?php
$db='mysqli';
$dbversion='8.0';
$host='localhost';
$user='user';
$pass='password';
$dbs='database';
$client_charset='utf8mb4';

Thx for the help in advance.

Carsten Aevermann avatar
cn flag
so one cleaned up the code but the full version had alle the question in it, nioce :-) Reformatting the file by deleting all comments wont help.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.