Dimitrios Desyllas
Dimitrios Desyllas

Reputation: 10028

Cannot find the environmental parameter

I have the following one line script:

sudo env WORDPRESS_MYSQL_ROOT_PASSWORD="passwd" \
    WORDPRESS_MYSQL_USER="wordpress" \
    WORDPRESS_MYSQL_PASSWORD="wordpress" \
    WORDPRESS_ADMIN_USER="admin" \
    WORDPRESS_ADMIN_PASSWORD="admin" \
    WORDPRESS_URL="http://0.0.0.0:8080" \
    docker run \
        --volume "/home/pcmagas/Kwdikas/docker/piwik-with-wordpress/scripts/../data/wordpress/db":/var/lib/mysql \
        --volume /home/pcmagas/Kwdikas/docker/piwik-with-wordpress/scripts/../restore/wordpress/db:/docker-entrypoint-initdb.d \
        -e MYSQL_ROOT_PASSWORD=$WORDPRESS_MYSQL_ROOT_PASSWORD \
        -e MYSQL_DATABASE="wordpress" \
        -e MYSQL_USER=$WORDPRESS_MYSQL_USER \
        -e MYSQL_PASSWORD=$WORDPRESS_MYSQL_PASSWORD \
    mariadb

But for some reason I get the error:

error: database is uninitialized and password option is not specified You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD

That means that for some reason cannot find the $WORDPRESS_MYSQL_ROOT_PASSWORD environmental parameter. Why is this?

Upvotes: 1

Views: 113

Answers (1)

Jens
Jens

Reputation: 72639

This can't work because setting a variable with

env FOO=BAR cmd

doesn't make the variable FOO available to the shell to expand it in

-e MYSQL_USER=$FOO

In other words, it it fails for the same reason as

FOO=BAR echo $FOO

doesn't output BAR. The shell expands $FOO before it invokes echo. You get the idea? Instead you should use something along

FOO=BAR; echo $FOO

Upvotes: 2

Related Questions