首页 > 其他分享 >docker踩坑之 device or resource busy

docker踩坑之 device or resource busy

时间:2024-04-09 22:44:19浏览次数:19  
标签:busy false redis var conf device docker null

问题描述

linux 服务器上运行了一个 docker 容器,在运行 cp 命令时报错

docker cp redis.conf myadmin_redis:/data/redis.conf

将服务器上的文件拷贝到 docker 容器内部时,报以下错误

Error response from daemon: Error processing tar file(exit status 1): unlinkat /data/redis.conf: device or resource busy

说 /data/redis.conf 文件被占用,不能拷贝。

具体原因

网上查了很多,没找到具体原因,后来才想起来,这个文件是容器创建时通过 volume 绑定的,不是一个真正的文件,启动命令如下。

 docker run -d --name myadmin_redis -p 6379:6379 -v /root/test_springboot/redis.conf:/data/redis.conf redis redis-server /data/redis.conf

可以看到,容器内的 /data/redis.conf 文件实际上是关联的 /root/test_springboot/redis.conf 文件,所以不能被拷贝修改。这种情况我们直接修改 /root/test_springboot/redis.conf 文件就可以了。

扩展

如果我们在容器运行后,忘了之前的启动命令,有以下两种方式可以帮忙查看。

第一种方式

查看系统操作历史命令

history | grep ''docker run'' | grep redis

适用于 该服务器上平时执行的命令比较少的情况,这样之前的历史命令才不会被冲掉。

第二种方式

查看容器的底层信息,返回一个 json 格式的详细结果,从中就可以看到 volume 绑定等信息。

docker inspect myadmin_redis

结果如下

点击查看详情
[
    {
        "Id": "d8d84e34168fb4fa59ab4d4a135820d4d8a96c208c971561546fcec6a16a06e5",
        "Created": "2022-07-13T12:10:23.532491402Z",
        "Path": "docker-entrypoint.sh",
        "Args": [
            "redis-server",
            "/data/redis.conf"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 2629113,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2024-03-16T14:04:01.320295425Z",
            "FinishedAt": "2024-03-16T14:01:00.75868032Z"
        },
        "Image": "sha256:3534610348b5abc4a6f6f7c314b5884a51c251e50f0038cb74d28c08cc7dd2a0",
        "ResolvConfPath": "/var/lib/docker/containers/d8d84e34168fb4fa59ab4d4a135820d4d8a96c208c971561546fcec6a16a06e5/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/d8d84e34168fb4fa59ab4d4a135820d4d8a96c208c971561546fcec6a16a06e5/hostname",
        "HostsPath": "/var/lib/docker/containers/d8d84e34168fb4fa59ab4d4a135820d4d8a96c208c971561546fcec6a16a06e5/hosts",
        "LogPath": "/var/lib/docker/containers/d8d84e34168fb4fa59ab4d4a135820d4d8a96c208c971561546fcec6a16a06e5/d8d84e34168fb4fa59ab4d4a135820d4d8a96c208c971561546fcec6a16a06e5-json.log",
        "Name": "/myadmin_redis",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": [
                "/root/test_springboot/redis.conf:/data/redis.conf"
            ],
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": {
                "6379/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "6379"
                    }
                ]
            },
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "CgroupnsMode": "host",
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "private",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "ConsoleSize": [
                0,
                0
            ],
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": [],
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DeviceCgroupRules": null,
            "DeviceRequests": null,
            "KernelMemory": 0,
            "KernelMemoryTCP": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": false,
            "PidsLimit": null,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0,
            "MaskedPaths": [
                "/proc/asound",
                "/proc/acpi",
                "/proc/kcore",
                "/proc/keys",
                "/proc/latency_stats",
                "/proc/timer_list",
                "/proc/timer_stats",
                "/proc/sched_debug",
                "/proc/scsi",
                "/sys/firmware"
            ],
            "ReadonlyPaths": [
                "/proc/bus",
                "/proc/fs",
                "/proc/irq",
                "/proc/sys",
                "/proc/sysrq-trigger"
            ]
        },
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/e15371bd5c5d3106f1997d6b340c9498a072e55da938427091d849e2ba674273-init/diff:/var/lib/docker/overlay2/4c29e88a5c7745ebd58ec99dcfd45a505b3737165dd55a71a865f5f3fb8e66b2/diff:/var/lib/docker/overlay2/48d224e8f73e0d3d66ca83d9b7a8cb8ca73515a51a617447c65d8cf7d9378971/diff:/var/lib/docker/overlay2/670ddc27302cdadc0c5db99de262e129d4068763fe9e12cd77aafbdc77cc1fb4/diff:/var/lib/docker/overlay2/9e522ad99ec5f1469fbc78c7cdb742cad47875a937d773db27097e00f04c0773/diff:/var/lib/docker/overlay2/312674f0181ffc96f651757926ee9fd4419498c88d3cfd0181c8528fa25680a4/diff:/var/lib/docker/overlay2/de095bfcbb1e8e76be121f4f5e23f3d46be21fab41ab382bd08de8afbf6296e1/diff",
                "MergedDir": "/var/lib/docker/overlay2/e15371bd5c5d3106f1997d6b340c9498a072e55da938427091d849e2ba674273/merged",
                "UpperDir": "/var/lib/docker/overlay2/e15371bd5c5d3106f1997d6b340c9498a072e55da938427091d849e2ba674273/diff",
                "WorkDir": "/var/lib/docker/overlay2/e15371bd5c5d3106f1997d6b340c9498a072e55da938427091d849e2ba674273/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [
            {
                "Type": "bind",
                "Source": "/root/test_springboot/redis.conf",
                "Destination": "/data/redis.conf",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            },
            {
                "Type": "volume",
                "Name": "c3a6e95da330454445e03619faf55cc48f57c79727ad86477504eec365b3f2f6",
                "Source": "/var/lib/docker/volumes/c3a6e95da330454445e03619faf55cc48f57c79727ad86477504eec365b3f2f6/_data",
                "Destination": "/data",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            }
        ],
        "Config": {
            "Hostname": "d8d84e34168f",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "6379/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "GOSU_VERSION=1.14",
                "REDIS_VERSION=7.0.3",
                "REDIS_DOWNLOAD_URL=http://download.redis.io/releases/redis-7.0.3.tar.gz",
                "REDIS_DOWNLOAD_SHA=2cde7d17214ffe305953da9fff12333e8a72caa57fd4923e4872f6362a208e73"
            ],
            "Cmd": [
                "redis-server",
                "/data/redis.conf"
            ],
            "Image": "redis",
            "Volumes": {
                "/data": {}
            },
            "WorkingDir": "/data",
            "Entrypoint": [
                "docker-entrypoint.sh"
            ],
            "OnBuild": null,
            "Labels": {}
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "fb5b7e1f10a85b9470732b7c9754eaae2e871751438c8f0f84ce62a5406d890e",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "6379/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "6379"
                    },
                    {
                        "HostIp": "::",
                        "HostPort": "6379"
                    }
                ]
            },
            "SandboxKey": "/var/run/docker/netns/fb5b7e1f10a8",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "f75c2cfba6bbfb8f456324c66e82318720090019f6e5f6d6b9c59125d374082e",
            "Gateway": "172.17.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.5",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:11:00:05",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "7a77e40525a22a4de0a2557bb00ea1b463fb5a1bdfd249463dd313d22f233154",
                    "EndpointID": "f75c2cfba6bbfb8f456324c66e82318720090019f6e5f6d6b9c59125d374082e",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.5",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:05",
                    "DriverOpts": null
                }
            }
        }
    }
]

参考

查看正在运行docker容器的启动命令
运维笔记 -- 如何查看运行中的容器,当初的启动命令

标签:busy,false,redis,var,conf,device,docker,null
From: https://www.cnblogs.com/strongmore/p/18077817

相关文章

  • 4-3 docker隔离机制-cgroups
    ControlGroup控制组群使用CGroups限制这个环境的资源使用情况cgroup:比如一台16核32GB的机器上只让容器使用2核4GB。使用CGroups还可以为资源设置权重,计算使用量,操控任务(进程或线程)启停等;在/sys/fs/cgroup下面有很多如cpu、memory这样的子目录,也叫子系统,这些都是这台机器......
  • 4-2 docker隔离机制-namespace
    1、使用Namespaces实现了系统环境的隔离Docker实际上是在创建容器进程时,指定了这个进程所需要启用的一组Namespace参数,这样容器就只能看到当前Namespace所限定的资源、文件、设备、状态。而对于宿主机以及其他不相干的程序,就完全看不见了http://www.dockone.io/article/8148常......
  • 4-1 Docker容器实现原理
    Docker容器实现原理主要是namespace和cgroup控制资源的隔离。虽然Docker可透过Namespace的方式分隔出看似是独立的空间,然而Linux内核(Kernel)却不能Namespace,所以即使有多个Container,所有的systemcall其实都是通过主机的内核处理,这便为Docker留下了不可否认的安全问题。虚拟机......
  • 2-3、dockerfile之wordpress
    wordpress:4.2#cddocker-training/wordpress/#ls-a.license.txtwp-config-sample.phpwp-login.php..readme.htmlwp-contentwp-mail.phpDockerfilewp-activate.phpwp-cron.php......
  • 2-2、dockerfile之php-fpm,mysql
    dockerfile之php-fpm#cddocker-training/php-fpm/#lsDockerfilenginx_nginx.confsupervisor_nginx.confnginx_default.confphp_www.confsupervisor_php-fpm.conf各文件解释:nginx_nginx.conf替换默认的nginx.conf文件nginx_default.conf替换默......
  • 1-1、Docker命令详解
    Docker命令详解#docker--helpUsage:docker[OPTIONS]COMMAND[arg...]dockerdaemon[--help|...]docker[-h|--help|-v|--version]Aself-sufficientruntimeforcontainers.主要选项:-d:以后台进行方式运行容器-t:提供一个伪终端-......
  • 1-2、docker命令
    docker命令1run主要选项:-d:以后台进行方式运行容器-t:提供一个伪终端-i:提供交互输入,一般与“-t”一起使用,如果只提供“-i”选项,则容器启动后是无法退出的-v:映射一个volume给容器,如:-p/data/www:/var/www/html-p:将容器的端口映射给宿主机(指定映射出的端口),......
  • 2-1、dockerfile之centos7
    docker基础及dockerfile1、docker组件(C/S)dockerclient:docker客户端dockerserver:dockerdaemon的主要组成部分,接受用户通过dockerclient发送的请求,并按照相应的路由规则实现路由分发docker镜像:docker镜像运行之后变成容器(dockerrun)dockerregistry:镜像仓库,registry......
  • 1-0 docker介绍
    dockerdocker与传统的虚拟化方式相比:docker的启动在秒级;docker对系统资源利用率高,一台主机可以同时运行多个docker容器;docker基本不消耗系统资源,使得运行在docker里面的应用的性能很高;更快的支付和部署:开发者可以使用一个标准的镜像来构建一套开发容器,开发完成后,运维人员可......
  • 【Linux】虚拟化技术docker搭建SuitoCRM系统及汉化
    CRM系统CRM(CustomerRelationshipManagement,客户关系管理)系统是一种用于管理和优化企业与客户关系的软件工具。在商业竞争激烈的现代社会中,CRM系统已成为许多企业提高销售、增强客户满意度和实现持续增长的重要工具。本文将介绍CRM系统的概念、功能以及其在企业中的重要性......