Answers: <p>CMD with brackets is contained within an array. Without brackets, the command is executed as <code>/bin/sh -c mysqld</code>.  Best practice afaik is to always use brackets. </p>
  
Answers: CC BY-SA 3.0
Answers: 2017-05-14T22:05:35.780Z
Answers: 2017-05-15T09:07:09.070Z
Answers: 2017-05-15T09:07:09.070Z
Answers: szinck
Body: <p>Why does <code>CMD ["mysqld"]</code> result in:</p>
  
  <pre><code>db_1   | 2017-05-14T16:34:11.829163Z 0 [Note] mysqld (mysqld 5.7.18) starting as process 1 ...
  db_1   | 2017-05-14T16:34:11.833159Z 0 [Note] InnoDB: PUNCH HOLE support available
  db_1   | 2017-05-14T16:34:11.833190Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
  db_1   | 2017-05-14T16:34:11.833199Z 0 [Note] InnoDB: Uses event mutexes
  db_1   | 2017-05-14T16:34:11.833211Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
  db_1   | 2017-05-14T16:34:11.833222Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3
  db_1   | 2017-05-14T16:34:11.833232Z 0 [Note] InnoDB: Using Linux native AIO
  db_1   | 2017-05-14T16:34:11.833583Z 0 [Note] InnoDB: Number of pools: 1
  db_1   | 2017-05-14T16:34:11.833729Z 0 [Note] InnoDB: Using CPU crc32 instructions
  db_1   | 2017-05-14T16:34:11.835500Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
  db_1   | 2017-05-14T16:34:11.844395Z 0 [Note] InnoDB: Completed initialization of buffer pool
  db_1   | 2017-05-14T16:34:11.846532Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
  </code></pre>
  
  <p>and <code>CMD mysqld</code> in:</p>
  
  <pre><code>db_1   | 2017-05-14T16:35:43.121085Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
  db_1   | 2017-05-14T16:35:43.123152Z 0 [Note] mysqld (mysqld 5.7.18) starting as process 8 ...
  db_1   | 2017-05-14T16:35:43.126844Z 0 [ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!
  db_1   | 
  db_1   | 2017-05-14T16:35:43.126882Z 0 [ERROR] Aborting
  db_1   | 
  db_1   | 2017-05-14T16:35:43.126905Z 0 [Note] Binlog end
  db_1   | 2017-05-14T16:35:43.127142Z 0 [Note] mysqld: Shutdown complete
  db_1   | 
  strength_db_1 exited with code 1
  </code></pre>
  
Tags: <dockerfile>
Title: What is the difference between using brackets (`[` `]`) and just specifying the command in the CMD option in Dockerfiles?
UserDisplayName: 030
ThreadText: # What is the difference between using brackets (`[` `]`) and just specifying the command in the CMD option in Dockerfiles?
  
  (Asked by: username_0 on 2017-05-14)
  
  Why does `CMD ["mysqld"]` result in:
  
  ```
  db_1   | 2017-05-14T16:34:11.829163Z 0 [Note] mysqld (mysqld 5.7.18) starting as process 1 ...
  db_1   | 2017-05-14T16:34:11.833159Z 0 [Note] InnoDB: PUNCH HOLE support available
  db_1   | 2017-05-14T16:34:11.833190Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
  db_1   | 2017-05-14T16:34:11.833199Z 0 [Note] InnoDB: Uses event mutexes
  db_1   | 2017-05-14T16:34:11.833211Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
  db_1   | 2017-05-14T16:34:11.833222Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3
  db_1   | 2017-05-14T16:34:11.833232Z 0 [Note] InnoDB: Using Linux native AIO
  db_1   | 2017-05-14T16:34:11.833583Z 0 [Note] InnoDB: Number of pools: 1
  db_1   | 2017-05-14T16:34:11.833729Z 0 [Note] InnoDB: Using CPU crc32 instructions
  db_1   | 2017-05-14T16:34:11.835500Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
  db_1   | 2017-05-14T16:34:11.844395Z 0 [Note] InnoDB: Completed initialization of buffer pool
  db_1   | 2017-05-14T16:34:11.846532Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
  
  ```
  
  and `CMD mysqld` in:
  
  ```
  db_1   | 2017-05-14T16:35:43.121085Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
  db_1   | 2017-05-14T16:35:43.123152Z 0 [Note] mysqld (mysqld 5.7.18) starting as process 8 ...
  db_1   | 2017-05-14T16:35:43.126844Z 0 [ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!
  db_1   | 
  db_1   | 2017-05-14T16:35:43.126882Z 0 [ERROR] Aborting
  db_1   | 
  db_1   | 2017-05-14T16:35:43.126905Z 0 [Note] Binlog end
  db_1   | 2017-05-14T16:35:43.127142Z 0 [Note] mysqld: Shutdown complete
  db_1   | 
  strength_db_1 exited with code 1
  
  ```
  
  **Tags:** dockerfile
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-05-14. Score: 10 | Accepted answer
  
  CMD with brackets is contained within an array. Without brackets, the command is executed as `/bin/sh -c mysqld`. Best practice afaik is to always use brackets.
  
  
  ---
  
  