Answers: <p>You can run the container in detached mode by passing <code>-d</code> or <code>--detach</code> with the run command: <a href="https://docs.docker.com/engine/reference/run/#detached-vs-foreground" rel="nofollow noreferrer">https://docs.docker.com/engine/reference/run/#detached-vs-foreground</a></p>
  
Answers: CC BY-SA 4.0
Answers: 2020-09-01T14:46:37.873Z
Answers: 2020-09-01T20:56:42.667Z
Answers: 2020-09-01T20:56:42.667Z
Answers: Argyle
Body: <p>How can I <a href="https://devops.stackexchange.com/q/12317/23443">create</a> a <code>MySQL</code> docker container as below in the background:</p>
  <pre><code>root:~# 
  root:~# docker run -e MYSQL_ROOT_PASSWORD=pass --name sql-db -p 3306:3306 mysql &amp;
  [1] 137878
  root:~# 2020-09-01 08:25:52+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.21-1debian10 started.
  2020-09-01 08:25:52+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
  2020-09-01 08:25:52+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.21-1debian10 started.
  2020-09-01 08:25:52+00:00 [Note] [Entrypoint]: Initializing database files
  2020-09-01T08:25:52.978020Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.21) initializing of server in progress as process 42
  2020-09-01T08:25:52.986993Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
  
  root:~# 
  root:~# 2020-09-01T08:26:03.346159Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
  2020-09-01T08:26:29.360246Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
  
  root:~# 
  root:~# 2020-09-01 08:27:35+00:00 [Note] [Entrypoint]: Database files initialized
  2020-09-01 08:27:35+00:00 [Note] [Entrypoint]: Starting temporary server
  2020-09-01T08:27:35.640682Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.21) starting as process 89
  2020-09-01T08:27:35.782142Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
  2020-09-01T08:27:37.207138Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
  2020-09-01T08:27:37.562152Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: /var/run/mysqld/mysqlx.sock
  2020-09-01T08:27:38.036662Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
  2020-09-01T08:27:38.036911Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
  2020-09-01T08:27:38.071799Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
  2020-09-01T08:27:38.105387Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.21'  socket: '/var/run/mysqld/mysqld.sock'  port: 0  MySQL Community Server - GPL.
  2020-09-01 08:27:38+00:00 [Note] [Entrypoint]: Temporary server started.
  Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
  Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
  Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
  Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
  
  2020-09-01 08:27:51+00:00 [Note] [Entrypoint]: Stopping temporary server
  2020-09-01T08:27:51.591046Z 10 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down mysqld (Version: 8.0.21).
  2020-09-01T08:28:09.444982Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.21)  MySQL Community Server - GPL.
  2020-09-01 08:28:09+00:00 [Note] [Entrypoint]: Temporary server stopped
  
  2020-09-01 08:28:09+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
  
  2020-09-01T08:28:10.181619Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.21) starting as process 1
  2020-09-01T08:28:10.297757Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
  2020-09-01T08:28:11.863493Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
  2020-09-01T08:28:12.702126Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
  2020-09-01T08:28:14.231915Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
  2020-09-01T08:28:14.232156Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
  2020-09-01T08:28:14.470976Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
  2020-09-01T08:28:14.498996Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.21'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server - GPL.
  
  root:~# 
  root:~# 
  root:~# docker container ls
  CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
  8a63d8b9d9c2        mysql               &quot;docker-entrypoint.s…&quot;   2 minutes ago       Up 2 minutes        0.0.0.0:3306-&gt;3306/tcp, 33060/tcp   sql-db
  root:~# 
  root:~# docker exec -it 8a63d8b9d9c2 bash
  root@8a63d8b9d9c2:/# 
  root@8a63d8b9d9c2:/# 
  </code></pre>
  <p>so that it's a bit less spammy?</p>
  <p>(Yes, I could just switch to another terminal, using something like <code>tmux</code>, or route output to <code>/dev/null</code> of course.)</p>
  
Tags: <docker><containers><bash><images><mysql>
Title: How to create a "silent" MySQL docker container?
UserDisplayName: Nicholas Saunders
ThreadText: # How to create a "silent" MySQL docker container?
  
  (Asked by: username_0 on 2020-09-01)
  
  How can I [create](https://devops.stackexchange.com/q/12317/23443) a `MySQL` docker container as below in the background:
  
  ```
  root:~# 
  root:~# docker run -e MYSQL_ROOT_PASSWORD=pass --name sql-db -p 3306:3306 mysql &
  [1] 137878
  root:~# 2020-09-01 08:25:52+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.21-1debian10 started.
  2020-09-01 08:25:52+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
  2020-09-01 08:25:52+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.21-1debian10 started.
  2020-09-01 08:25:52+00:00 [Note] [Entrypoint]: Initializing database files
  2020-09-01T08:25:52.978020Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.21) initializing of server in progress as process 42
  2020-09-01T08:25:52.986993Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
  
  root:~# 
  root:~# 2020-09-01T08:26:03.346159Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
  2020-09-01T08:26:29.360246Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
  
  root:~# 
  root:~# 2020-09-01 08:27:35+00:00 [Note] [Entrypoint]: Database files initialized
  2020-09-01 08:27:35+00:00 [Note] [Entrypoint]: Starting temporary server
  2020-09-01T08:27:35.640682Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.21) starting as process 89
  2020-09-01T08:27:35.782142Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
  2020-09-01T08:27:37.207138Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
  2020-09-01T08:27:37.562152Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: /var/run/mysqld/mysqlx.sock
  2020-09-01T08:27:38.036662Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
  2020-09-01T08:27:38.036911Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
  2020-09-01T08:27:38.071799Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
  2020-09-01T08:27:38.105387Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.21'  socket: '/var/run/mysqld/mysqld.sock'  port: 0  MySQL Community Server - GPL.
  2020-09-01 08:27:38+00:00 [Note] [Entrypoint]: Temporary server started.
  Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
  Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
  Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
  Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
  
  2020-09-01 08:27:51+00:00 [Note] [Entrypoint]: Stopping temporary server
  2020-09-01T08:27:51.591046Z 10 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down mysqld (Version: 8.0.21).
  2020-09-01T08:28:09.444982Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.21)  MySQL Community Server - GPL.
  2020-09-01 08:28:09+00:00 [Note] [Entrypoint]: Temporary server stopped
  
  2020-09-01 08:28:09+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
  
  2020-09-01T08:28:10.181619Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.21) starting as process 1
  2020-09-01T08:28:10.297757Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
  2020-09-01T08:28:11.863493Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
  2020-09-01T08:28:12.702126Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
  2020-09-01T08:28:14.231915Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
  2020-09-01T08:28:14.232156Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
  2020-09-01T08:28:14.470976Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
  2020-09-01T08:28:14.498996Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.21'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server - GPL.
  
  root:~# 
  root:~# 
  root:~# docker container ls
  CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
  8a63d8b9d9c2        mysql               "docker-entrypoint.s…"   2 minutes ago       Up 2 minutes        0.0.0.0:3306->3306/tcp, 33060/tcp   sql-db
  root:~# 
  root:~# docker exec -it 8a63d8b9d9c2 bash
  root@8a63d8b9d9c2:/# 
  root@8a63d8b9d9c2:/# 
  
  ```
  
  so that it's a bit less spammy?
  
  (Yes, I could just switch to another terminal, using something like `tmux`, or route output to `/dev/null` of course.)
  
  **Tags:** docker, containers, bash, images, mysql
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-09-01. Score: 3 | Accepted answer
  
  You can run the container in detached mode by passing `-d` or `--detach` with the run command: <https://docs.docker.com/engine/reference/run/#detached-vs-foreground>
  
  
  ---
  
  