Answers: <p>The default Dockerfile shell is <code>sh</code>. I don't think echo there has the <code>-e</code> modifier for backslash. Newline &amp; other special symbols will work by default. In your command, resulting <code>.my.cnf</code> would contain a litteral <code>-e</code>.</p>
  <p>Remove <code>-e</code> <strong>or</strong> use the original command in Dockerfile in a different shell, for instance:</p>
  <pre><code>RUN /bin/bash -c '&lt;your-command&gt;'
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2021-04-02T07:18:34.953Z
Answers: 2021-04-02T07:18:34.953Z
Answers: apo
Body: <p>I'm trying to create a <code>.my.cnf</code> file for my MySQL docker-container that would allow me to prefill the user and password for the MySQL client. To achieve this I created the following dockerfile:</p>
  <pre><code>FROM mysql:5.7
  RUN touch ~/.my.cnf &amp;&amp; echo -e &quot;[client]\nuser=root\npassword=$(echo $MYSQL_ROOT_PASSWORD)&quot; &gt;&gt; ~/.my.cnf
  </code></pre>
  <p>But when starting the container I always get the errors:</p>
  <pre><code>mysql5.7-database    | 2021-04-01 18:38:51+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.33-1debian10 started.
  mysql5.7-database    | 2021-04-01 18:38:51+00:00 [ERROR] [Entrypoint]: mysqld failed while attempting to check config
  mysql5.7-database    |  command was: mysqld --verbose --help --log-bin-index=/tmp/tmp.5imGsNRXXC
  mysql5.7-database    |  mysqld: [ERROR] Found option without preceding group in config file /root/.my.cnf at line 1!
  mysql5.7-database    | mysqld: [ERROR] Fatal error in defaults handling. Program aborted!
  </code></pre>
  <ul>
  <li>The environment variable <code>$MYSQL_ROOT_PASSWORD</code> is successfully set with the correct password.</li>
  <li>I can login with the password in the <code>$MYSQL_ROOT_PASSWORD</code></li>
  </ul>
  <p>The result of <code>echo -e &quot;[client]\nuser=root\npassword=$(echo $MYSQL_ROOT_PASSWORD)&quot;</code> is:</p>
  <pre><code>[client]
  user=root
  password=&lt;my-generated-password&gt;
  </code></pre>
  <p>When I create the <code>.my.cnf</code> file manually in the running docker container, it works like a charm. Any advise?</p>
  
Tags: <docker><mysql>
Title: mysqld: [ERROR] Found option without preceding group in config file /root/.my.cnf at line 1!
UserDisplayName: Beach Chicken
ThreadText: # mysqld: [ERROR] Found option without preceding group in config file /root/.my.cnf at line 1!
  
  (Asked by: username_0 on 2021-04-01)
  
  I'm trying to create a `.my.cnf` file for my MySQL docker-container that would allow me to prefill the user and password for the MySQL client. To achieve this I created the following dockerfile:
  
  ```
  FROM mysql:5.7
  RUN touch ~/.my.cnf && echo -e "[client]\nuser=root\npassword=$(echo $MYSQL_ROOT_PASSWORD)" >> ~/.my.cnf
  
  ```
  
  But when starting the container I always get the errors:
  
  ```
  mysql5.7-database    | 2021-04-01 18:38:51+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.33-1debian10 started.
  mysql5.7-database    | 2021-04-01 18:38:51+00:00 [ERROR] [Entrypoint]: mysqld failed while attempting to check config
  mysql5.7-database    |  command was: mysqld --verbose --help --log-bin-index=/tmp/tmp.5imGsNRXXC
  mysql5.7-database    |  mysqld: [ERROR] Found option without preceding group in config file /root/.my.cnf at line 1!
  mysql5.7-database    | mysqld: [ERROR] Fatal error in defaults handling. Program aborted!
  
  ```
  
  * The environment variable `$MYSQL_ROOT_PASSWORD` is successfully set with the correct password.
  * I can login with the password in the `$MYSQL_ROOT_PASSWORD`
  
  The result of `echo -e "[client]\nuser=root\npassword=$(echo $MYSQL_ROOT_PASSWORD)"` is:
  
  ```
  [client]
  user=root
  password=<my-generated-password>
  
  ```
  
  When I create the `.my.cnf` file manually in the running docker container, it works like a charm. Any advise?
  
  **Tags:** docker, mysql
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-04-02. Score: 1
  
  The default Dockerfile shell is `sh`. I don't think echo there has the `-e` modifier for backslash. Newline & other special symbols will work by default. In your command, resulting `.my.cnf` would contain a litteral `-e`.
  
  Remove `-e` **or** use the original command in Dockerfile in a different shell, for instance:
  
  ```
  RUN /bin/bash -c '<your-command>'
  
  ```
  
  
  ---
  
  