Docker cp is not completely copied in the shell script, but it is no problem to execute the commands in the script line by line. The code is as follows:

  docker, question
#!  /bin/bash
 
 # Pull Mirror
 sudo docker pull mysql:5.7.21
 
 # Create Directory
 sudo mkdir /opt/mysql_5.7.21
 # Used to get unmapped
 sudo docker run -p 3306:3306 --name mysql_5.7.21 -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7.21
 
 sudo docker cp mysql_5.7.21:/etc/mysql /opt/mysql_5.7.21/etc
 sudo docker cp mysql_5.7.21:/var/log/mysql /opt/mysql_5.7.21/logs
 sudo docker cp mysql_5.7.21:/var/lib/mysql /opt/mysql_5.7.21/data
 
 # Remove Mirror
 sudo docker stop mysql_5.7.21 && sudo docker rm mysql_5.7.21
 
 # Really Execute and Map Directories
 sudo docker run -p 3306:3306 --name mysql_5.7.21 \
 -v /opt/mysql_5.7.21/etc:/etc/mysql:ro \
 -v /opt/mysql_5.7.21/logs:/var/log/mysql \
 -v /opt/mysql_5.7.21/data:/var/lib/mysql \
 -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7.21

Incomplete copying of files in the /opt/mysql_5.7.21/data directory will occur after the script is executed.
Thereby causing the container to fail to run.
Useif [ $? -eq 0 ]; thenTo wait is still invalid

Seek advice from the great god

Cp to add -r parameter to recursively copy files