问题遇到的现象和发生背景
初学者,在docker上练习安装mysql数据库,使用了如下命令
docker run -d --name my-mysql -p 3307:3306 -e MYSQL_ROOT_PASSWORD=123456 \
>-v /opt/my-docker/mysql/data:/var/liv/mysql \
>-v /opt/my-docker/mysql/conf.d:/etc/mysql/conf.d \
>-v /opt/my-docker/mysql/log:/var/log/mysql \
>mysql:5.7
执行结果如下:
第一,容器被建立且处于运行状态
第二,在宿主机指定目录下并未出现任何文件
第三,在volume容器卷中出现了一个mysql的匿名挂载
[root@localhost data]# docker run -d --name my-mysql -p 3307:3306 -e MYSQL_ROOT_PASSWORD=123456 -v /opt/my-docker/mysql/data:/var/liv/mysql -v /opt/my-docker/mysql/conf.d:/etc/mysql/conf.d -v /opt/my-docker/mysql/log:/var/log/mysql mysql:5.7
ca8ef7fe2dca5b7596f0511923453d28a361b73c759ee94652982f085750d547
[root@localhost data]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ca8ef7fe2dca mysql:5.7 "docker-entrypoint..." 35 seconds ago Up 34 seconds 33060/tcp, 0.0.0.0:3307->3306/tcp my-mysql
[root@localhost data]# cd /opt/my-docker/mysql/data
[root@localhost data]# ll -a
total 0
drwxr-xr-x 2 root root 6 Jun 26 23:28 .
drwxr-xr-x 5 root root 43 Jun 26 23:28 ..
[root@localhost data]# docker volume ls
DRIVER VOLUME NAME
local 05866638dd852a4c289e11d8911ceb943b81de099d965b3523b22f6f0e2a5b10
[root@localhost data]# docker volume inspect 05866638dd852a4c289e11d8911ceb943b81de099d965b3523b22f6f0e2a5b10
[
{
"Driver": "local",
"Labels": null,
"Mountpoint": "/var/lib/docker/volumes/05866638dd852a4c289e11d8911ceb943b81de099d965b3523b22f6f0e2a5b10/_data",
"Name": "05866638dd852a4c289e11d8911ceb943b81de099d965b3523b22f6f0e2a5b10",
"Options": {},
"Scope": "local"
}
]
[root@localhost data]# cd /var/lib/docker/volumes/05866638dd852a4c289e11d8911ceb943b81de099d965b3523b22f6f0e2a5b10/_data
[root@localhost _data]# ll -a
total 188484
drwxrwxrwx 5 polkitd input 328 Jun 26 23:28 .
drwxr-xr-x 3 root root 19 Jun 26 23:28 ..
-rw-r----- 1 polkitd input 56 Jun 26 23:28 auto.cnf
-rw------- 1 polkitd input 1680 Jun 26 23:28 ca-key.pem
-rw-r--r-- 1 polkitd input 1112 Jun 26 23:28 ca.pem
-rw-r--r-- 1 polkitd input 1112 Jun 26 23:28 client-cert.pem
-rw------- 1 polkitd input 1680 Jun 26 23:28 client-key.pem
-rw-r----- 1 polkitd input 1352 Jun 26 23:28 ib_buffer_pool
-rw-r----- 1 polkitd input 79691776 Jun 26 23:28 ibdata1
-rw-r----- 1 polkitd input 50331648 Jun 26 23:28 ib_logfile0
-rw-r----- 1 polkitd input 50331648 Jun 26 23:28 ib_logfile1
-rw-r----- 1 polkitd input 12582912 Jun 26 23:28 ibtmp1
drwxr-x--- 2 polkitd input 4096 Jun 26 23:28 mysql
drwxr-x--- 2 polkitd input 8192 Jun 26 23:28 performance_schema
-rw------- 1 polkitd input 1680 Jun 26 23:28 private_key.pem
-rw-r--r-- 1 polkitd input 452 Jun 26 23:28 public_key.pem
-rw-r--r-- 1 polkitd input 1112 Jun 26 23:28 server-cert.pem
-rw------- 1 polkitd input 1680 Jun 26 23:28 server-key.pem
drwxr-x--- 2 polkitd input 8192 Jun 26 23:28 sys
执行完成以后,容器被成功建立并运行。然后尝试在用远程数据库管理软件给这个数据库新建一个test库。
然后再查看volume中的那个匿名挂载文件夹,发现多了一个test。我觉得基本就可以确定,这个匿名挂载卷就是刚才我创建的mysql的挂载。
操作环境、软件版本等信息
操作系统是centos7.5 ,mysql是5.7 ,docker是1.13.1
容器日志:
[root@localhost _data]# docker logs my-mysql
2022-06-26 15:28:34+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.38-1debian10 started.
2022-06-26 15:28:34+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2022-06-26 15:28:34+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.38-1debian10 started.
2022-06-26 15:28:34+00:00 [Note] [Entrypoint]: Initializing database files
2022-06-26T15:28:34.359871Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-06-26T15:28:34.585836Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-06-26T15:28:34.626430Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-06-26T15:28:34.687497Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: a47da3f0-f564-11ec-8158-0242ac110002.
2022-06-26T15:28:34.688931Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-06-26T15:28:34.847892Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-06-26T15:28:34.847946Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-06-26T15:28:34.848575Z 0 [Warning] CA certificate ca.pem is self signed.
2022-06-26T15:28:34.871934Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2022-06-26 15:28:36+00:00 [Note] [Entrypoint]: Database files initialized
2022-06-26 15:28:36+00:00 [Note] [Entrypoint]: Starting temporary server
2022-06-26 15:28:36+00:00 [Note] [Entrypoint]: Waiting for server startup
2022-06-26T15:28:36.945586Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-06-26T15:28:36.946863Z 0 [Note] mysqld (mysqld 5.7.38) starting as process 78 ...
2022-06-26T15:28:36.951333Z 0 [Note] InnoDB: PUNCH HOLE support available
2022-06-26T15:28:36.951391Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2022-06-26T15:28:36.951395Z 0 [Note] InnoDB: Uses event mutexes
2022-06-26T15:28:36.951397Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2022-06-26T15:28:36.951399Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2022-06-26T15:28:36.951403Z 0 [Note] InnoDB: Using Linux native AIO
2022-06-26T15:28:36.951575Z 0 [Note] InnoDB: Number of pools: 1
2022-06-26T15:28:36.951671Z 0 [Note] InnoDB: Using CPU crc32 instructions
2022-06-26T15:28:36.953542Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2022-06-26T15:28:36.970392Z 0 [Note] InnoDB: Completed initialization of buffer pool
2022-06-26T15:28:36.975428Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2022-06-26T15:28:36.990544Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2022-06-26T15:28:36.999804Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2022-06-26T15:28:36.999895Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2022-06-26T15:28:37.023591Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2022-06-26T15:28:37.024454Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2022-06-26T15:28:37.024497Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2022-06-26T15:28:37.025410Z 0 [Note] InnoDB: 5.7.38 started; log sequence number 2749976
2022-06-26T15:28:37.025650Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2022-06-26T15:28:37.026357Z 0 [Note] Plugin 'FEDERATED' is disabled.
2022-06-26T15:28:37.028742Z 0 [Note] InnoDB: Buffer pool(s) load completed at 220626 15:28:37
2022-06-26T15:28:37.034857Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
2022-06-26T15:28:37.034897Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
2022-06-26T15:28:37.034902Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-06-26T15:28:37.034904Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-06-26T15:28:37.035398Z 0 [Warning] CA certificate ca.pem is self signed.
2022-06-26T15:28:37.035484Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
2022-06-26T15:28:37.036595Z 0 [Warning] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2022-06-26T15:28:37.044039Z 0 [Note] Event Scheduler: Loaded 0 events
2022-06-26T15:28:37.044424Z 0 [Note] mysqld: ready for connections.
Version: '5.7.38' socket: '/var/run/mysqld/mysqld.sock' port: 0 MySQL Community Server (GPL)
2022-06-26 15:28:37+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.
2022-06-26 15:28:39+00:00 [Note] [Entrypoint]: Stopping temporary server
2022-06-26T15:28:39.655774Z 0 [Note] Giving 0 client threads a chance to die gracefully
2022-06-26T15:28:39.655820Z 0 [Note] Shutting down slave threads
2022-06-26T15:28:39.655827Z 0 [Note] Forcefully disconnecting 0 remaining clients
2022-06-26T15:28:39.655832Z 0 [Note] Event Scheduler: Purging the queue. 0 events
2022-06-26T15:28:39.655888Z 0 [Note] Binlog end
2022-06-26T15:28:39.656588Z 0 [Note] Shutting down plugin 'ngram'
2022-06-26T15:28:39.656617Z 0 [Note] Shutting down plugin 'partition'
2022-06-26T15:28:39.656620Z 0 [Note] Shutting down plugin 'BLACKHOLE'
2022-06-26T15:28:39.656623Z 0 [Note] Shutting down plugin 'ARCHIVE'
2022-06-26T15:28:39.656628Z 0 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'
2022-06-26T15:28:39.656673Z 0 [Note] Shutting down plugin 'MRG_MYISAM'
2022-06-26T15:28:39.656677Z 0 [Note] Shutting down plugin 'MyISAM'
2022-06-26T15:28:39.656688Z 0 [Note] Shutting down plugin 'INNODB_SYS_VIRTUAL'
2022-06-26T15:28:39.656691Z 0 [Note] Shutting down plugin 'INNODB_SYS_DATAFILES'
2022-06-26T15:28:39.656692Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES'
2022-06-26T15:28:39.656694Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS'
2022-06-26T15:28:39.656695Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN'
2022-06-26T15:28:39.656697Z 0 [Note] Shutting down plugin 'INNODB_SYS_FIELDS'
2022-06-26T15:28:39.656698Z 0 [Note] Shutting down plugin 'INNODB_SYS_COLUMNS'
2022-06-26T15:28:39.656700Z 0 [Note] Shutting down plugin 'INNODB_SYS_INDEXES'
2022-06-26T15:28:39.656701Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS'
2022-06-26T15:28:39.656703Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLES'
2022-06-26T15:28:39.656704Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE'
2022-06-26T15:28:39.656705Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE'
2022-06-26T15:28:39.656707Z 0 [Note] Shutting down plugin 'INNODB_FT_CONFIG'
2022-06-26T15:28:39.656708Z 0 [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED'
2022-06-26T15:28:39.656710Z 0 [Note] Shutting down plugin 'INNODB_FT_DELETED'
2022-06-26T15:28:39.656712Z 0 [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD'
2022-06-26T15:28:39.656713Z 0 [Note] Shutting down plugin 'INNODB_METRICS'
2022-06-26T15:28:39.656714Z 0 [Note] Shutting down plugin 'INNODB_TEMP_TABLE_INFO'
2022-06-26T15:28:39.656716Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS'
2022-06-26T15:28:39.656717Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU'
2022-06-26T15:28:39.656719Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE'
2022-06-26T15:28:39.656720Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET'
2022-06-26T15:28:39.656721Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX'
2022-06-26T15:28:39.656723Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET'
2022-06-26T15:28:39.656724Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM'
2022-06-26T15:28:39.656726Z 0 [Note] Shutting down plugin 'INNODB_CMP_RESET'
2022-06-26T15:28:39.656727Z 0 [Note] Shutting down plugin 'INNODB_CMP'
2022-06-26T15:28:39.656729Z 0 [Note] Shutting down plugin 'INNODB_LOCK_WAITS'
2022-06-26T15:28:39.656730Z 0 [Note] Shutting down plugin 'INNODB_LOCKS'
2022-06-26T15:28:39.656732Z 0 [Note] Shutting down plugin 'INNODB_TRX'
2022-06-26T15:28:39.656733Z 0 [Note] Shutting down plugin 'InnoDB'
2022-06-26T15:28:39.656821Z 0 [Note] InnoDB: FTS optimize thread exiting.
2022-06-26T15:28:39.656947Z 0 [Note] InnoDB: Starting shutdown...
2022-06-26T15:28:39.757749Z 0 [Note] InnoDB: Dumping buffer pool(s) to /var/lib/mysql/ib_buffer_pool
2022-06-26T15:28:39.758359Z 0 [Note] InnoDB: Buffer pool(s) dump completed at 220626 15:28:39
2022-06-26T15:28:40.867683Z 0 [Note] InnoDB: Shutdown completed; log sequence number 12659904
2022-06-26T15:28:40.868723Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
2022-06-26T15:28:40.868786Z 0 [Note] Shutting down plugin 'MEMORY'
2022-06-26T15:28:40.868797Z 0 [Note] Shutting down plugin 'CSV'
2022-06-26T15:28:40.868806Z 0 [Note] Shutting down plugin 'sha256_password'
2022-06-26T15:28:40.868809Z 0 [Note] Shutting down plugin 'mysql_native_password'
2022-06-26T15:28:40.868927Z 0 [Note] Shutting down plugin 'binlog'
2022-06-26T15:28:40.869452Z 0 [Note] mysqld: Shutdown complete
2022-06-26 15:28:41+00:00 [Note] [Entrypoint]: Temporary server stopped
2022-06-26 15:28:41+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
2022-06-26T15:28:41.826763Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-06-26T15:28:41.829217Z 0 [Note] mysqld (mysqld 5.7.38) starting as process 1 ...
2022-06-26T15:28:41.833358Z 0 [Note] InnoDB: PUNCH HOLE support available
2022-06-26T15:28:41.833401Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2022-06-26T15:28:41.833405Z 0 [Note] InnoDB: Uses event mutexes
2022-06-26T15:28:41.833407Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2022-06-26T15:28:41.833409Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2022-06-26T15:28:41.833413Z 0 [Note] InnoDB: Using Linux native AIO
2022-06-26T15:28:41.833601Z 0 [Note] InnoDB: Number of pools: 1
2022-06-26T15:28:41.833695Z 0 [Note] InnoDB: Using CPU crc32 instructions
2022-06-26T15:28:41.834907Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2022-06-26T15:28:41.841702Z 0 [Note] InnoDB: Completed initialization of buffer pool
2022-06-26T15:28:41.843338Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2022-06-26T15:28:41.855941Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2022-06-26T15:28:41.863940Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2022-06-26T15:28:41.864047Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2022-06-26T15:28:41.876055Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2022-06-26T15:28:41.876965Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2022-06-26T15:28:41.877023Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2022-06-26T15:28:41.877694Z 0 [Note] InnoDB: Waiting for purge to start
2022-06-26T15:28:41.928214Z 0 [Note] InnoDB: 5.7.38 started; log sequence number 12659904
2022-06-26T15:28:41.928605Z 0 [Note] Plugin 'FEDERATED' is disabled.
2022-06-26T15:28:41.928913Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2022-06-26T15:28:41.932057Z 0 [Note] InnoDB: Buffer pool(s) load completed at 220626 15:28:41
2022-06-26T15:28:41.933508Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
2022-06-26T15:28:41.933546Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
2022-06-26T15:28:41.933550Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-06-26T15:28:41.933552Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-06-26T15:28:41.934010Z 0 [Warning] CA certificate ca.pem is self signed.
2022-06-26T15:28:41.934055Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
2022-06-26T15:28:41.934467Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
2022-06-26T15:28:41.934560Z 0 [Note] IPv6 is available.
2022-06-26T15:28:41.934595Z 0 [Note] - '::' resolves to '::';
2022-06-26T15:28:41.934611Z 0 [Note] Server socket created on IP: '::'.
2022-06-26T15:28:41.935353Z 0 [Warning] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2022-06-26T15:28:41.941874Z 0 [Note] Event Scheduler: Loaded 0 events
2022-06-26T15:28:41.942103Z 0 [Note] mysqld: ready for connections.
Version: '5.7.38' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server (GPL)
2022-06-26T15:38:08.717095Z 2 [Warning] IP address '192.168.66.10' could not be resolved: Name or service not known
尝试过的解决方法
重复多次,也查了好多资料,但是和我这个情况都不太一样。具名挂载也是这个状况,可以启动运行,宿主机文件夹也被创立,但是是空的,只是会增加一个匿名挂载卷。
我想要达到的结果
指定路径挂载和具名挂载的指令可以正常执行,而不是执行后就变成匿名挂载。
初学者,希望各位多多指教,谢谢啦。