这里小编想说明的是,当我们文件挂载之后,再对容器里面的文件进行CRUD操作时,会出现mv: cannot move ‘XXX’ to ‘XXX’: Device or resource busy,因为文件被挂载之后就不会被允许在容器中操作
1.现象
[root@localhost ROOT]# docker exec -it 7f696eb7e082 /bin/bash
root@7f696eb7e082:/usr/local/tomcat# ls
BUILDING.txt LICENSE README.md RUNNING.txt conf logs temp work
CONTRIBUTING.md NOTICE RELEASE-NOTES bin lib native-jni-lib webapps.dist
root@7f696eb7e082:/usr/local/tomcat# mv webapps.dist webapps2
mv: cannot move 'webapps.dist' to 'webapps2': Device or resource busy
2.使用df -h 查看
3.解决:换个挂载文件夹路径,即可解决问题
例如:
然后就执行CRUD即可
对应的挂载目录对应,即可直接在挂载文件操作
访问正常
4.执行代码流程
[root@localhost var]# docker run -d -p 8080:8080 -v mTM03:/usr/local/tomcat/webapps --name mTM01 tomcat
c99ae49240e21c43d528618207d70d59b1810ab267cdd9574c0ca3116755334c
[root@localhost var]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c99ae49240e2 tomcat "catalina.sh run" 4 seconds ago Up 1 second 0.0.0.0:8080->8080/tcp mTM01
[root@localhost var]# ls
adm cache crash db empty games gopher kerberos lib local lock log mail nis opt preserve run spool tmp var yp
[root@localhost var]# cd /var/lib/docker/volumes
[root@localhost volumes]# ls
057ae3b802c7f31b2355b6ef1284bc0520798ebba8c2c658edd9dde211e84c34 dc5dad70d7c7246158c963b3161cbf292a937d1f37fcd83962c6767b7a36c20e
7052a3c69a024c65828f2014e28947332816fb144d840c62cdaea34bd8cdc45b dca6f5306ea0a55d4b4988d198fe0b1e0a560bbbaa215d1247582edc5bbf9e66
874007e2b3c7fe6529a777efb7a96831dba19439814d835f2b4aa056f731d01b f65e7709bdd7c916e3559f4893dc3e418a3f5f4717d99b13f2f965f1ceeb7241
89953ca415537e028f151851f6a8b268e51f29a0d4b86c7bd714d36ad58ff608 metadata.db
af03341de5e24615139da2aafc29d757afd08394feafb60d7d975fd1e9ce673c mTM03
b092a4595bd00736848d7cef69442b23b627ac01ee652942705f02b4a4f5ed1b
[root@localhost volumes]# cd mTM03/
[root@localhost mTM03]# ls
_data
[root@localhost mTM03]# cd _data/
[root@localhost _data]# ls
进入容器操作
[root@localhost _data]# docker exec -it c99ae49240e2 /bin/bash
root@c99ae49240e2:/usr/local/tomcat# ls
BUILDING.txt LICENSE README.md RUNNING.txt conf logs temp webapps.dist
CONTRIBUTING.md NOTICE RELEASE-NOTES bin lib native-jni-lib webapps work
root@c99ae49240e2:/usr/local/tomcat# mv webapps.dist webapps
root@c99ae49240e2:/usr/local/tomcat# ls
BUILDING.txt LICENSE README.md RUNNING.txt conf logs temp work
CONTRIBUTING.md NOTICE RELEASE-NOTES bin lib native-jni-lib webapps
root@c99ae49240e2:/usr/local/tomcat# cd webapps
root@c99ae49240e2:/usr/local/tomcat/webapps# ls
webapps.dist