docker安装mysql5.7

  1. docker hub官网mysql地址

https://hub.docker.com/_/mysql

  • 选择Tags可以查看相关的版本信息,选择你需要的版本tag。

  1. docker常用命令

  • docker help

  • 查看帮助。

xiaosa@XIAOSAdeMacBook-Pro ~ % docker help

Usage:  docker [OPTIONS] COMMAND

A self-sufficient runtime for containers

Options:
      --config string      Location of client config files (default "/Users/xiaosa/.docker")
  -c, --context string     Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context set with "docker context use")
  -D, --debug              Enable debug mode
  -H, --host list          Daemon socket(s) to connect to
  -l, --log-level string   Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
      --tls                Use TLS; implied by --tlsverify
      --tlscacert string   Trust certs signed only by this CA (default "/Users/xiaosa/.docker/ca.pem")
      --tlscert string     Path to TLS certificate file (default "/Users/xiaosa/.docker/cert.pem")
      --tlskey string      Path to TLS key file (default "/Users/xiaosa/.docker/key.pem")
      --tlsverify          Use TLS and verify the remote
  -v, --version            Print version information and quit

Management Commands:
  builder     Manage builds
  buildx*     Docker Buildx (Docker Inc., v0.10.0)
  compose*    Docker Compose (Docker Inc., v2.15.1)
  config      Manage Docker configs
  container   Manage containers
  context     Manage contexts
  dev*        Docker Dev Environments (Docker Inc., v0.0.5)
  extension*  Manages Docker extensions (Docker Inc., v0.2.17)
  image       Manage images
  manifest    Manage Docker image manifests and manifest lists
  network     Manage networks
  node        Manage Swarm nodes
  plugin      Manage plugins
  sbom*       View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc., 0.6.0)
  scan*       Docker Scan (Docker Inc., v0.23.0)
  secret      Manage Docker secrets
  service     Manage services
  stack       Manage Docker stacks
  swarm       Manage Swarm
  system      Manage Docker
  trust       Manage trust on Docker images
  volume      Manage volumes

Commands:
  attach      Attach local standard input, output, and error streams to a running container
  build       Build an image from a Dockerfile
  commit      Create a new image from a container's changes
  cp          Copy files/folders between a container and the local filesystem
  create      Create a new container
  diff        Inspect changes to files or directories on a container's filesystem
  events      Get real time events from the server
  exec        Run a command in a running container
  export      Export a container's filesystem as a tar archive
  history     Show the history of an image
  images      List images
  import      Import the contents from a tarball to create a filesystem image
  info        Display system-wide information
  inspect     Return low-level information on Docker objects
  kill        Kill one or more running containers
  load        Load an image from a tar archive or STDIN
  login       Log in to a Docker registry
  logout      Log out from a Docker registry
  logs        Fetch the logs of a container
  pause       Pause all processes within one or more containers
  port        List port mappings or a specific mapping for the container
  ps          List containers
  pull        Pull an image or a repository from a registry
  push        Push an image or a repository to a registry
  rename      Rename a container
  restart     Restart one or more containers
  rm          Remove one or more containers
  rmi         Remove one or more images
  run         Run a command in a new container
  save        Save one or more images to a tar archive (streamed to STDOUT by default)
  search      Search the Docker Hub for images
  start       Start one or more stopped containers
  stats       Display a live stream of container(s) resource usage statistics
  stop        Stop one or more running containers
  tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
  top         Display the running processes of a container
  unpause     Unpause all processes within one or more containers
  update      Update configuration of one or more containers
  version     Show the Docker version information
  wait        Block until one or more containers stop, then print their exit codes

Run 'docker COMMAND --help' for more information on a command.

To get more help with docker, check out our guides at https://docs.docker.com/go/guides/
  • docker images

  • 查看本地所有镜像。

xiaosa@XIAOSAdeMacBook-Pro ~ % docker images
REPOSITORY           TAG       IMAGE ID       CREATED       SIZE
mysql/mysql-server   5.7       a4ad24fe52cd   7 weeks ago   432MB
  • docker run

  • docker run imageName启动一个容器。

xiaosa@XIAOSAdeMacBook-Pro ~ % docker run --name mysql5.7 mysql/mysql-server:5.7
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
[Entrypoint] MySQL Docker Image 5.7.41-1.2.11-server
[Entrypoint] No password option specified for new database.
[Entrypoint]   A random onetime password will be generated.
[Entrypoint] Initializing database
2023-03-09T11:55:59.537469Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2023-03-09T11:55:59.583240Z 0 [ERROR] InnoDB: Linux Native AIO interface is not supported on this platform. Please check your OS documentation and install appropriate binary of InnoDB.
2023-03-09T11:55:59.584940Z 0 [Warning] InnoDB: Linux Native AIO disabled.
2023-03-09T11:55:59.807242Z 0 [Warning] InnoDB: New log files created, LSN=45790
2023-03-09T11:55:59.885464Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2023-03-09T11:55:59.986177Z 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: 5bd89b71-be71-11ed-8694-0242ac110002.
2023-03-09T11:55:59.991133Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2023-03-09T11:56:00.874679Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2023-03-09T11:56:00.874755Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2023-03-09T11:56:00.881680Z 0 [Warning] CA certificate ca.pem is self signed.
2023-03-09T11:56:01.050295Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
[Entrypoint] Database initialized
2023-03-09T11:56:03.699817Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2023-03-09T11:56:03.706044Z 0 [Note] mysqld (mysqld 5.7.41) starting as process 75 ...
2023-03-09T11:56:03.744041Z 0 [Note] InnoDB: PUNCH HOLE support available
2023-03-09T11:56:03.745655Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2023-03-09T11:56:03.745763Z 0 [Note] InnoDB: Uses event mutexes
2023-03-09T11:56:03.745863Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2023-03-09T11:56:03.745967Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.12
2023-03-09T11:56:03.746044Z 0 [Note] InnoDB: Using Linux native AIO
2023-03-09T11:56:03.751459Z 0 [Note] InnoDB: Number of pools: 1
2023-03-09T11:56:03.753084Z 0 [Note] InnoDB: Using CPU crc32 instructions
2023-03-09T11:56:03.755021Z 0 [ERROR] InnoDB: Linux Native AIO interface is not supported on this platform. Please check your OS documentation and install appropriate binary of InnoDB.
2023-03-09T11:56:03.755217Z 0 [Note] InnoDB: You can disable Linux Native AIO by setting innodb_use_native_aio = 0 in my.cnf
2023-03-09T11:56:03.755395Z 0 [Warning] InnoDB: Linux Native AIO disabled.
2023-03-09T11:56:03.758566Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2023-03-09T11:56:03.804093Z 0 [Note] InnoDB: Completed initialization of buffer pool
2023-03-09T11:56:03.821697Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2023-03-09T11:56:03.841719Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2023-03-09T11:56:03.908539Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2023-03-09T11:56:03.911609Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2023-03-09T11:56:03.926103Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2023-03-09T11:56:03.931688Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2023-03-09T11:56:03.931768Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2023-03-09T11:56:03.939081Z 0 [Note] InnoDB: Waiting for purge to start
2023-03-09T11:56:03.990463Z 0 [Note] InnoDB: 5.7.41 started; log sequence number 2762314
2023-03-09T11:56:03.993075Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2023-03-09T11:56:03.998830Z 0 [Note] Plugin 'FEDERATED' is disabled.
2023-03-09T11:56:04.020127Z 0 [Note] InnoDB: Buffer pool(s) load completed at 230309 11:56:04
2023-03-09T11:56:04.049769Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
2023-03-09T11:56:04.049859Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
2023-03-09T11:56:04.049943Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2023-03-09T11:56:04.049980Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2023-03-09T11:56:04.065263Z 0 [Warning] CA certificate ca.pem is self signed.
2023-03-09T11:56:04.066358Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
2023-03-09T11:56:04.112961Z 0 [Note] Event Scheduler: Loaded 0 events
2023-03-09T11:56:04.114458Z 0 [Note] mysqld: ready for connections.
Version: '5.7.41'  socket: '/var/lib/mysql/mysql.sock'  port: 0  MySQL Community Server (GPL)
2023-03-09T11:56:04.285019Z 3 [Note] InnoDB: Stopping purge
2023-03-09T11:56:04.303126Z 3 [Note] InnoDB: Resuming purge
2023-03-09T11:56:04.312195Z 3 [Note] InnoDB: Stopping purge
2023-03-09T11:56:04.329441Z 3 [Note] InnoDB: Resuming purge
2023-03-09T11:56:04.331333Z 3 [Note] InnoDB: Stopping purge
2023-03-09T11:56:04.333834Z 3 [Note] InnoDB: Resuming purge
2023-03-09T11:56:04.335137Z 3 [Note] InnoDB: Stopping purge
2023-03-09T11:56:04.337418Z 3 [Note] InnoDB: Resuming purge
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/leapseconds' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/tzdata.zi' 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.
[Entrypoint] GENERATED ROOT PASSWORD: 5R45BQ.04k&r6*Vd*tR@2.^N_LKulg4M

[Entrypoint] ignoring /docker-entrypoint-initdb.d/*

2023-03-09T11:56:09.299330Z 0 [Note] Giving 0 client threads a chance to die gracefully
2023-03-09T11:56:09.299442Z 0 [Note] Shutting down slave threads
2023-03-09T11:56:09.299518Z 0 [Note] Forcefully disconnecting 0 remaining clients
2023-03-09T11:56:09.299729Z 0 [Note] Event Scheduler: Purging the queue. 0 events
2023-03-09T11:56:09.300284Z 0 [Note] Binlog end
2023-03-09T11:56:09.302868Z 0 [Note] Shutting down plugin 'ngram'
2023-03-09T11:56:09.302962Z 0 [Note] Shutting down plugin 'partition'
2023-03-09T11:56:09.303019Z 0 [Note] Shutting down plugin 'BLACKHOLE'
2023-03-09T11:56:09.303158Z 0 [Note] Shutting down plugin 'ARCHIVE'
2023-03-09T11:56:09.303198Z 0 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'
2023-03-09T11:56:09.303519Z 0 [Note] Shutting down plugin 'MRG_MYISAM'
2023-03-09T11:56:09.303556Z 0 [Note] Shutting down plugin 'MyISAM'
2023-03-09T11:56:09.303755Z 0 [Note] Shutting down plugin 'INNODB_SYS_VIRTUAL'
2023-03-09T11:56:09.303802Z 0 [Note] Shutting down plugin 'INNODB_SYS_DATAFILES'
2023-03-09T11:56:09.303821Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES'
2023-03-09T11:56:09.303829Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS'
2023-03-09T11:56:09.303843Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN'
2023-03-09T11:56:09.303850Z 0 [Note] Shutting down plugin 'INNODB_SYS_FIELDS'
2023-03-09T11:56:09.303858Z 0 [Note] Shutting down plugin 'INNODB_SYS_COLUMNS'
2023-03-09T11:56:09.303865Z 0 [Note] Shutting down plugin 'INNODB_SYS_INDEXES'
2023-03-09T11:56:09.303876Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS'
2023-03-09T11:56:09.303882Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLES'
2023-03-09T11:56:09.303888Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE'
2023-03-09T11:56:09.303894Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE'
2023-03-09T11:56:09.303900Z 0 [Note] Shutting down plugin 'INNODB_FT_CONFIG'
2023-03-09T11:56:09.303906Z 0 [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED'
2023-03-09T11:56:09.303912Z 0 [Note] Shutting down plugin 'INNODB_FT_DELETED'
2023-03-09T11:56:09.303919Z 0 [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD'
2023-03-09T11:56:09.303931Z 0 [Note] Shutting down plugin 'INNODB_METRICS'
2023-03-09T11:56:09.303937Z 0 [Note] Shutting down plugin 'INNODB_TEMP_TABLE_INFO'
2023-03-09T11:56:09.303944Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS'
2023-03-09T11:56:09.303951Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU'
2023-03-09T11:56:09.303957Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE'
2023-03-09T11:56:09.303963Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET'
2023-03-09T11:56:09.303969Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX'
2023-03-09T11:56:09.303975Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET'
2023-03-09T11:56:09.303981Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM'
2023-03-09T11:56:09.303986Z 0 [Note] Shutting down plugin 'INNODB_CMP_RESET'
2023-03-09T11:56:09.303992Z 0 [Note] Shutting down plugin 'INNODB_CMP'
2023-03-09T11:56:09.303998Z 0 [Note] Shutting down plugin 'INNODB_LOCK_WAITS'
2023-03-09T11:56:09.304004Z 0 [Note] Shutting down plugin 'INNODB_LOCKS'
2023-03-09T11:56:09.304010Z 0 [Note] Shutting down plugin 'INNODB_TRX'
2023-03-09T11:56:09.304016Z 0 [Note] Shutting down plugin 'InnoDB'
2023-03-09T11:56:09.304711Z 0 [Note] InnoDB: FTS optimize thread exiting.
2023-03-09T11:56:09.306550Z 0 [Note] InnoDB: Starting shutdown...
2023-03-09T11:56:09.409574Z 0 [Note] InnoDB: Dumping buffer pool(s) to /var/lib/mysql/ib_buffer_pool
2023-03-09T11:56:09.411338Z 0 [Note] InnoDB: Buffer pool(s) dump completed at 230309 11:56:09
2023-03-09T11:56:10.504927Z 0 [Note] InnoDB: Shutdown completed; log sequence number 12184404
2023-03-09T11:56:10.509337Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
2023-03-09T11:56:10.509647Z 0 [Note] Shutting down plugin 'MEMORY'
2023-03-09T11:56:10.509766Z 0 [Note] Shutting down plugin 'CSV'
2023-03-09T11:56:10.509829Z 0 [Note] Shutting down plugin 'sha256_password'
2023-03-09T11:56:10.509841Z 0 [Note] Shutting down plugin 'mysql_native_password'
2023-03-09T11:56:10.510416Z 0 [Note] Shutting down plugin 'binlog'
2023-03-09T11:56:10.522303Z 0 [Note] mysqld: Shutdown complete

[Entrypoint] Server shut down
[Entrypoint] Setting root user as expired. Password will need to be changed before database can be used.

[Entrypoint] MySQL init process done. Ready for start up.

[Entrypoint] Starting MySQL 5.7.41-1.2.11-server
2023-03-09T11:56:11.727246Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2023-03-09T11:56:11.732815Z 0 [Note] mysqld (mysqld 5.7.41) starting as process 1 ...
2023-03-09T11:56:11.766232Z 0 [Note] InnoDB: PUNCH HOLE support available
2023-03-09T11:56:11.767662Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2023-03-09T11:56:11.767735Z 0 [Note] InnoDB: Uses event mutexes
2023-03-09T11:56:11.767818Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2023-03-09T11:56:11.767916Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.12
2023-03-09T11:56:11.767999Z 0 [Note] InnoDB: Using Linux native AIO
2023-03-09T11:56:11.772798Z 0 [Note] InnoDB: Number of pools: 1
2023-03-09T11:56:11.774343Z 0 [Note] InnoDB: Using CPU crc32 instructions
2023-03-09T11:56:11.776090Z 0 [ERROR] InnoDB: Linux Native AIO interface is not supported on this platform. Please check your OS documentation and install appropriate binary of InnoDB.
2023-03-09T11:56:11.776253Z 0 [Note] InnoDB: You can disable Linux Native AIO by setting innodb_use_native_aio = 0 in my.cnf
2023-03-09T11:56:11.776511Z 0 [Warning] InnoDB: Linux Native AIO disabled.
2023-03-09T11:56:11.780029Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2023-03-09T11:56:11.825440Z 0 [Note] InnoDB: Completed initialization of buffer pool
2023-03-09T11:56:11.842512Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2023-03-09T11:56:11.864562Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2023-03-09T11:56:11.933621Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2023-03-09T11:56:11.935222Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2023-03-09T11:56:11.948283Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2023-03-09T11:56:11.954026Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2023-03-09T11:56:11.954119Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2023-03-09T11:56:11.961262Z 0 [Note] InnoDB: Waiting for purge to start
2023-03-09T11:56:12.017447Z 0 [Note] InnoDB: 5.7.41 started; log sequence number 12184404
2023-03-09T11:56:12.020151Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2023-03-09T11:56:12.025038Z 0 [Note] Plugin 'FEDERATED' is disabled.
2023-03-09T11:56:12.069872Z 0 [Note] InnoDB: Buffer pool(s) load completed at 230309 11:56:12
2023-03-09T11:56:12.072929Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
2023-03-09T11:56:12.073007Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
2023-03-09T11:56:12.073104Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2023-03-09T11:56:12.073128Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2023-03-09T11:56:12.088195Z 0 [Warning] CA certificate ca.pem is self signed.
2023-03-09T11:56:12.089309Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
2023-03-09T11:56:12.092509Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
2023-03-09T11:56:12.093181Z 0 [Note] IPv6 is available.
2023-03-09T11:56:12.093506Z 0 [Note]   - '::' resolves to '::';
2023-03-09T11:56:12.093800Z 0 [Note] Server socket created on IP: '::'.
2023-03-09T11:56:12.144404Z 0 [Note] Event Scheduler: Loaded 0 events
2023-03-09T11:56:12.145259Z 0 [Note] Execution of init_file '/var/lib/mysql-files/d5A8fjIlh9' started.
2023-03-09T11:56:12.155516Z 0 [Note] Execution of init_file '/var/lib/mysql-files/d5A8fjIlh9' ended.
2023-03-09T11:56:12.156599Z 0 [Note] mysqld: ready for connections.
Version: '5.7.41'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MySQL Community Server (GPL)

  • docker ps

  • 查看本地运行中的容器。

xiaosa@XIAOSAdeMacBook-Pro ~ % docker ps    
CONTAINER ID   IMAGE                    COMMAND                  CREATED          STATUS                    PORTS                 NAMES
8ba34559a73d   mysql/mysql-server:5.7   "/entrypoint.sh mysq…"   26 minutes ago   Up 26 minutes (healthy)   3306/tcp, 33060/tcp   mysql5.7
  • docker ps -a,查看本地所有容器,包括没有运行的容器。

xiaosa@XIAOSAdeMacBook-Pro ~ % docker ps -a            
CONTAINER ID   IMAGE                    COMMAND                  CREATED          STATUS                     PORTS     NAMES
8ba34559a73d   mysql/mysql-server:5.7   "/entrypoint.sh mysq…"   32 minutes ago   Exited (0) 3 minutes ago             mysql5.7
  • docker stop

  • docker stop containerId/containerName ,停止一个容器。

xiaosa@XIAOSAdeMacBook-Pro ~ % docker stop 6e7d1d61d230
6e7d1d61d230
  • docker rm

  • docker rm containerId/containerName,删除一个容器。

xiaosa@XIAOSAdeMacBook-Pro ~ % docker rm 6e7d1d61d230
6e7d1d61d230
  • docker rmi

  • 删除一个镜像。

xiaosa@XIAOSAdeMacBook-Pro ~ % docker images         
REPOSITORY           TAG       IMAGE ID       CREATED       SIZE
mysql/mysql-server   5.7       a4ad24fe52cd   7 weeks ago   432MB
xiaosa@XIAOSAdeMacBook-Pro ~ % docker rmi a4ad24fe52cd
Untagged: mysql/mysql-server:5.7
Untagged: mysql/mysql-server@sha256:1178cdd375f758968cd834ac4057bae41307e64b7c69a9e145896e7b11f48064
Deleted: sha256:a4ad24fe52cdf82a35c6f2dae7670cfebf39357de983cb909db07c8b56df4dd1
Deleted: sha256:522d4bd955d841c9d9ee13768c45758adebc763f6ade609bf067567ec1f9db42
Deleted: sha256:0d4e56a725cdabce1459fceacb4ae726f01a3b74da88ae163828011a17695775
Deleted: sha256:3c0e6f8ea73046976b06eeb8643db4203d80e97582b772e033f539b79641b81b
Deleted: sha256:abde8b2762b759ea13f432207e38bd5af0b7f7a5a49e780e79499194ecbcfa39
Deleted: sha256:5836d1e6c9d144340d78e71f394fb81003df2e58146882e4ed1ea8eedf9a9e06
Deleted: sha256:5245f05f9eacc04eb63abf72ffba361c1834ffa6df119e7de7275be38f933673
Deleted: sha256:812f16602ebb1f9018247ecd71457fc2c9bb261ed03dde61daa8c204397fdbca
Deleted: sha256:62d9c4cbe8f4b26952ebb533b5336bf7af791db2b4288df65c9a685e1f2530cd
  1. docker安装mysql 5.7

  • 参数说明

  • --name mysql5.7,给启动的容器命名为“mysql5.7”。

  • -v /Users/xiaosa/learning/mysql/data:/var/lib/mysql/,将本地的/Users/xiaosa/learning/mysql/data目录挂载到容器的/var/lib/mysql/目录上,保证容器重新启动时数据不会丢失。

  • -e MYSQL_ROOT_PASSWORD=123456,设置mysql root的密码。

  • -e MYSQL_ROOT_HOST=%,设置允许链接的地址,%代表允许任何地址链接。

  • -p 3306:3306,本地端口与容器端口进行映射。

  • -d,以后台启动方式运行。

docker run --name mysql5.7 -v /Users/xiaosa/learning/mysql/data:/var/lib/mysql/ -e MYSQL_ROOT_PASSWORD=123456 -e MYSQL_ROOT_HOST=% -p 3306:3306 -d mysql/mysql-server:5.7
Unable to find image 'mysql/mysql-server:5.7' locally
5.7: Pulling from mysql/mysql-server
d70f3c0cccba: Pull complete 
e7dc89aa39f7: Pull complete 
76cc4215b650: Pull complete 
25b0bb53e492: Pull complete 
349b52643cc3: Pull complete 
62ddcf4a4134: Pull complete 
c91c597e717d: Pull complete 
c7e93886e496: Pull complete 
Digest: sha256:1178cdd375f758968cd834ac4057bae41307e64b7c69a9e145896e7b11f48064
Status: Downloaded newer image for mysql/mysql-server:5.7
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
88b161663c2c4cc2f76fab3bebec8de51660370c5139ae6eb6ef8c61a2dcedd7
  • 查看启动状态

xiaosa@XIAOSAdeMacBook-Pro data % docker ps
CONTAINER ID   IMAGE                    COMMAND                  CREATED          STATUS                    PORTS                               NAMES
88b161663c2c   mysql/mysql-server:5.7   "/entrypoint.sh mysq…"   48 seconds ago   Up 48 seconds (healthy)   0.0.0.0:3306->3306/tcp, 33060/tcp   mysql5.7
  • 宿主机使用Navicat进行连接测试。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值