容器启动后,如果想要修改容器挂载信息或其他配置信息,不重新删除容器的话,可以停止容器后修改容器配置文件,修改时需要先停止容器

    1. # 查看容器ID
    2. docker ps
    3. # 停止容器
    4. docker stop 容器ID
    5. # 此目录下文件夹对应容器列表
    6. cd /var/lib/docker/containers
    7. cd 容器ID
    8. vi config.v2.json

    image.png
    下文是nginx配置文件的举例,例如要修conf.d的改挂载地址,搜索MountPoints,在下文中找到
    image.png

    1. {
    2. "StreamConfig": {
    3. },
    4. "State": {
    5. "Running": true,
    6. "Paused": false,
    7. "Restarting": false,
    8. "OOMKilled": false,
    9. "RemovalInProgress": false,
    10. "Dead": false,
    11. "Pid": 8650,
    12. "ExitCode": 0,
    13. "Error": "",
    14. "StartedAt": "2022-04-01T07:30:50.731680798Z",
    15. "FinishedAt": "2022-04-01T07:30:46.907933433Z",
    16. "Health": null
    17. },
    18. "ID": "e892198d4792909c32bf645c78de662d0ed318ff4c14779dfc4cfcedf454add3",
    19. "Created": "2022-03-30T07:12:19.531076176Z",
    20. "Managed": false,
    21. "Path": "/docker-entrypoint.sh",
    22. "Args": [
    23. "nginx",
    24. "-g",
    25. "daemon off;"
    26. ],
    27. "Config": {
    28. "Hostname": "e892198d4792",
    29. "Domainname": "",
    30. "User": "",
    31. "AttachStdin": false,
    32. "AttachStdout": false,
    33. "AttachStderr": false,
    34. "ExposedPorts": {
    35. "80/tcp": {
    36. },
    37. "9000/tcp": {
    38. },
    39. "9020/tcp": {
    40. }
    41. },
    42. "Tty": true,
    43. "OpenStdin": true,
    44. "StdinOnce": false,
    45. "Env": [
    46. "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
    47. "NGINX_VERSION=1.21.6",
    48. "NJS_VERSION=0.7.2",
    49. "PKG_RELEASE=1~bullseye"
    50. ],
    51. "Cmd": [
    52. "nginx",
    53. "-g",
    54. "daemon off;"
    55. ],
    56. "Image": "nginx",
    57. "Volumes": null,
    58. "WorkingDir": "",
    59. "Entrypoint": [
    60. "/docker-entrypoint.sh"
    61. ],
    62. "OnBuild": null,
    63. "Labels": {
    64. "maintainer": "NGINX Docker Maintainers \u003cdocker-maint@nginx.com\u003e"
    65. },
    66. "StopSignal": "SIGQUIT"
    67. },
    68. "Image": "sha256:12766a6745eea133de9fdcd03ff720fa971fdaf21113d4bc72b417c123b15619",
    69. "NetworkSettings": {
    70. "Bridge": "",
    71. "SandboxID": "4d373bd98fc8199ba5b692e90b7de2cdd00743864f899064fd09ff51372488a9",
    72. "HairpinMode": false,
    73. "LinkLocalIPv6Address": "",
    74. "LinkLocalIPv6PrefixLen": 0,
    75. "Networks": {
    76. "bridge": {
    77. "IPAMConfig": null,
    78. "Links": null,
    79. "Aliases": null,
    80. "NetworkID": "f827685fcfd78b2992757fec5352f35ba03ff4a59d440b5285b73a4b5ca95374",
    81. "EndpointID": "2fd4f3cca1cbafecf4066e07a1377b8c238da5df8cf28080ff07473c1e2e660d",
    82. "Gateway": "172.18.0.1",
    83. "IPAddress": "172.18.0.2",
    84. "IPPrefixLen": 16,
    85. "IPv6Gateway": "",
    86. "GlobalIPv6Address": "",
    87. "GlobalIPv6PrefixLen": 0,
    88. "MacAddress": "02:42:ac:12:00:02",
    89. "DriverOpts": null,
    90. "IPAMOperational": false
    91. }
    92. },
    93. "Service": null,
    94. "Ports": {
    95. "80/tcp": null,
    96. "9000/tcp": [
    97. {
    98. "HostIp": "0.0.0.0",
    99. "HostPort": "9000"
    100. }
    101. ],
    102. "9020/tcp": [
    103. {
    104. "HostIp": "0.0.0.0",
    105. "HostPort": "9020"
    106. }
    107. ]
    108. },
    109. "SandboxKey": "/var/run/docker/netns/4d373bd98fc8",
    110. "SecondaryIPAddresses": null,
    111. "SecondaryIPv6Addresses": null,
    112. "IsAnonymousEndpoint": false,
    113. "HasSwarmEndpoint": false
    114. },
    115. "LogPath": "/var/lib/docker/containers/e892198d4792909c32bf645c78de662d0ed318ff4c14779dfc4cfcedf454add3/e892198d4792909c32bf645c78de662d0ed318ff4c14779dfc4cfcedf454add3-json.log",
    116. "Name": "/nginx",
    117. "Driver": "overlay2",
    118. "OS": "linux",
    119. "MountLabel": "",
    120. "ProcessLabel": "",
    121. "RestartCount": 0,
    122. "HasBeenStartedBefore": true,
    123. "HasBeenManuallyStopped": false,
    124. "MountPoints": {
    125. "/etc/nginx/conf.d": {
    126. "Source": "/root/nginx/conf.d",
    127. "Destination": "/etc/nginx/conf.d",
    128. "RW": true,
    129. "Name": "",
    130. "Driver": "",
    131. "Type": "bind",
    132. "Propagation": "rprivate",
    133. "Spec": {
    134. "Type": "bind",
    135. "Source": "/root/nginx/conf.d",
    136. "Target": "/etc/nginx/conf.d"
    137. },
    138. "SkipMountpointCreation": false
    139. },
    140. "/etc/nginx/nginx.conf": {
    141. "Source": "/root/nginx/nginx.conf",
    142. "Destination": "/etc/nginx/nginx.conf",
    143. "RW": true,
    144. "Name": "",
    145. "Driver": "",
    146. "Type": "bind",
    147. "Propagation": "rprivate",
    148. "Spec": {
    149. "Type": "bind",
    150. "Source": "/root/nginx/nginx.conf",
    151. "Target": "/etc/nginx/nginx.conf"
    152. },
    153. "SkipMountpointCreation": false
    154. },
    155. "/usr/local/nginx/9020/dist": {
    156. "Source": "/root/nginx/9020/dist",
    157. "Destination": "/usr/local/nginx/9020/dist",
    158. "RW": true,
    159. "Name": "",
    160. "Driver": "",
    161. "Type": "bind",
    162. "Propagation": "rprivate",
    163. "Spec": {
    164. "Type": "bind",
    165. "Source": "/root/nginx/9020/dist",
    166. "Target": "/usr/local/nginx/9020/dist"
    167. },
    168. "SkipMountpointCreation": false
    169. }
    170. },
    171. "SecretReferences": null,
    172. "ConfigReferences": null,
    173. "AppArmorProfile": "",
    174. "HostnamePath": "/var/lib/docker/containers/e892198d4792909c32bf645c78de662d0ed318ff4c14779dfc4cfcedf454add3/hostname",
    175. "HostsPath": "/var/lib/docker/containers/e892198d4792909c32bf645c78de662d0ed318ff4c14779dfc4cfcedf454add3/hosts",
    176. "ShmPath": "/var/lib/docker/containers/e892198d4792909c32bf645c78de662d0ed318ff4c14779dfc4cfcedf454add3/mounts/shm",
    177. "ResolvConfPath": "/var/lib/docker/containers/e892198d4792909c32bf645c78de662d0ed318ff4c14779dfc4cfcedf454add3/resolv.conf",
    178. "SeccompProfile": "",
    179. "NoNewPrivileges": false
    180. }