title: How to run a script shell just after the Dockerfile 'CMD ["mysqld"]'?
body: <p>I have a MariaDB image running on Docker container, which has to update its root password at each initialization, for security reasons. There is a vault server from which my container gets new password each time it initializes. After a new password is obtained, my script has to be run to login into MariaDB database and update the password. I have tried several strategies to run such script as soon as the MariaDB database is up and runnig, but no success up to now. I do use a Dockerfile to build my MariaDB extended image. At the end, there is a 'CMD ["mysqld"]' that starts up the service. The problem is that my script has to be run just after the "CMD ["mysqld"]" command, since it is the command that initializes MariaDB process and then the it becomes "Ready for connections".</p>
  
  <p>Is there any way to workaround this situation in order to run my shell script (["/foreground.sh"]) just after MariaDB service is up and runnig? It is important to recall that no human manipulation is allowed after the container is initialized. Therefore, every action has to take place via script shell, since this project is for a production environment, from where I have no access.</p>
  
  <h1>Relevant part of my Dockerfile</h1>
  
  <pre><code>VOLUME /var/lib/mysql
  EXPOSE 3306
  COPY docker-entrypoint.sh /
  COPY foreground.sh /
  RUN chmod +x /docker-entrypoint.sh /foreground.sh
  ENTRYPOINT ["/docker-entrypoint.sh"]
  CMD ["mysqld"] ["/foreground.sh"]
  </code></pre>
  
  <h1>Relevant part of my "foreground.sh"</h1>
  
  <pre><code>    mysql -u"root" -p"$ROOT_PASSWORD" &lt;&lt;MariaDB_INPUT
      UPDATE mysql.user SET authentication_string=PASSWORD("$MYSQL_ROOT_PASSWORD_NEW_VAULT") WHERE USER="root";
      UPDATE mysql.user SET authentication_string=PASSWORD("$MYSQL_PASSWORD_NEW_VAULT") WHERE USER="user";
      UPDATE mysql.user SET plugin="mysql_native_password";
      FLUSH PRIVILEGES;
      quit
  </code></pre>
  
  <p>MariaDB_INPUT</p>