docker启动Mysql

cs202@cs202-devbox:~$ sudo docker run -d mysql
7698fdd7a2d05d38cf19c60cc9e35c1117fc551ae5e319144947154f4f353d23
cs202@cs202-devbox:~$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
257646e19a08        ubuntu              "/bin/bash"         26 minutes ago      Up 13 minutes                           desperate_ardinghelli
cs202@cs202-devbox:~$ sudo docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS               NAMES
7698fdd7a2d0        mysql               "/entrypoint.sh mysql"   18 seconds ago      Exited (1) 17 seconds ago                       desperate_swanson
151a8113ba67        mysql               "/entrypoint.sh mysql"   5 minutes ago       Exited (1) 5 minutes ago                        hopeful_williams
257646e19a08        ubuntu              "/bin/bash"              27 minutes ago      Up 13 minutes                                   desperate_ardinghelli
发现并没有成功启动,查看日志:
cs202@cs202-devbox:~$ sudo docker logs desperate_swanson
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


于是设置MYSQL_ROOT_PASSWORD:
sudo docker run  -e MYSQL_ROOT_PASSWORD=wwwwww --name mysql -d mysql
总算启动成功了:
^Ccs202@cs202-devbox:~sudo docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
b50461bd8135        mysql               "/entrypoint.sh mysql"   4 minutes ago       Up 4 minutes        3306/tcp            mysql
257646e19a08        ubuntu              "/bin/bash"              37 minutes ago      Up 23 minutes                           desperate_ardinghelli
cs202@cs202-devbox:~$ 
后台打印出大片日志:
cs202@cs202-devbox:~$ sudo docker logs -f mysql
2016-03-12T02:50:26.302319Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2016-03-12T02:50:26.375013Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2016-03-12T02:50:26.375515Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2016-03-12T02:50:26.444508Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2016-03-12T02:50:26.446893Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2016-03-12T02:50:26.447017Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2016-03-12T02:50:26.451067Z 0 [Note] InnoDB: Waiting for purge to start
2016-03-12T02:50:26.504451Z 0 [Note] InnoDB: 5.7.11 started; log sequence number 11991512
2016-03-12T02:50:26.505028Z 0 [Note] Plugin 'FEDERATED' is disabled.
2016-03-12T02:50:26.508912Z 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key
2016-03-12T02:50:26.509170Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
2016-03-12T02:50:26.509310Z 0 [Note] IPv6 is available.
2016-03-12T02:50:26.509366Z 0 [Note]   - '::' resolves to '::';
2016-03-12T02:50:26.509419Z 0 [Note] Server socket created on IP: '::'.
2016-03-12T02:50:26.509154Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2016-03-12T02:50:26.519321Z 0 [Warning] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
2016-03-12T02:50:26.519569Z 0 [Warning] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
2016-03-12T02:50:26.544083Z 0 [Note] InnoDB: Buffer pool(s) load completed at 160312  2:50:26
2016-03-12T02:50:26.548848Z 0 [Warning] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
2016-03-12T02:50:26.565564Z 0 [Note] Event Scheduler: Loaded 0 events
2016-03-12T02:50:26.566266Z 0 [Note] mysqld: ready for connections.
Version: '5.7.11'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)




如果需要指定端口的话,加-p选项:
docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password -d mysql/mysql-server:latest

你可能感兴趣的:(docker)