2.3.컨테이너를 원격 컴퓨터처럼 사용하기

접속

  • 도커 컨테이너는 호스트 컴퓨터의 운영체제를 공유
  • 호스트 컴퓨터가 리눅스 머신이라면 리눅스 셸이 뜬다.
docker container run --interactive --tty diamol/base
or
docker container run -it diamol/base

docker container top

  • 대상 컨테이너에서 실행중인 프로세스의 목록을 보여준다.
  • 여기서는 1bb3c9ee963d 컨테이너를 대상으로 하기위해 1bb까지 지정
001)   ~ docker container top 1bb
002) UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
003) root                3092                3066                0                   00:57               ?                   00:00:00            npm run start
004) root                3350                3092                0                   00:57               ?                   00:00:02            node /usr/src/app/node_modules/.bin/next start

docker container logs

  • 대상 컨테이너에서 수집된 모든 로그를 출력
  • 도커는 애플리케이션의 표준 출력으로부터 로그를 수집
001)   ~ docker container logs 1bb
002) 
003) > mdground3@0.1.0 start
004) > next start
005) 
006) ready - started server on 0.0.0.0:3000, url: http://localhost:3000
007) info  - Loaded env from /usr/src/app/.env.production
008) Error: Truncated incorrect INTEGER value: 'undefined'
009)     at PromiseConnection.execute (/usr/src/app/node_modules/mysql2/promise.js:111:22)
010)     at /usr/src/app/.next/server/pages/api/trees/[id].js:195:49
011)     at Function.transactionExecutor (/usr/src/app/.next/server/chunks/276.js:102:28)
012)     at processTicksAndRejections (node:internal/process/task_queues:96:5) {
013)   code: 'ER_TRUNCATED_WRONG_VALUE',
014)   errno: 1292,
015)   sql: '\n' +
016)     '          UPDATE tree \n' +
017)     '          SET updated_datetime = CURRENT_TIMESTAMP\n' +
018)     '         , tree_content = ? \n' +
019)     '          WHERE user_id = ?\n' +
020)     '          AND tree_id = ?\n' +
021)     '        ',
022)   sqlState: '22007',
023)   sqlMessage: "Truncated incorrect INTEGER value: 'undefined'"
024) }
025) 
026) > mdground3@0.1.0 start
027) > next start
028) 
029) ready - started server on 0.0.0.0:3000, url: http://localhost:3000
030) info  - Loaded env from /usr/src/app/.env.production

docker container inspect

  • 대상 컨테이너의 상세한 정보를 보여준다.
  • 자동처리에 유리한 JSON 포맷
  • 가상 파일 시스템 상의 경로, 컨테이너에서 실행중인 명령, 해당 컨테이너가 접속된 가상 도커 네트워크 정보 등 애플리케이션에서 발생한 문제를 추적하는데 유용한 정보가 제공된다.
001)   ~ docker container inspect 1bb
002) [
003)     {
004)         "Id": "1bb3c9ee963de0e8e54f2c232860def17ca6ac9e57a1a80b8abb1dfd3ca50cda",
005)         "Created": "2023-05-30T07:17:03.996611923Z",
006)         "Path": "docker-entrypoint.sh",
007)         "Args": [
008)             "npm",
009)             "run",
010)             "start"
011)         ],
012)         "State": {
013)             "Status": "running",
014)             "Running": true,
015)             "Paused": false,
016)             "Restarting": false,
017)             "OOMKilled": false,
018)             "Dead": false,
019)             "Pid": 3092,
020)             "ExitCode": 0,
021)             "Error": "",
022)             "StartedAt": "2023-06-14T00:42:44.237179883Z",
023)             "FinishedAt": "2023-06-14T00:42:26.984908458Z"
024)         },
025)         "Image": "sha256:b5beda4c32e1c1f14906cabd7581b712d25f8098e3f2ce7e8fae98b533b99f06",
026)         "ResolvConfPath": "/var/lib/docker/containers/1bb3c9ee963de0e8e54f2c232860def17ca6ac9e57a1a80b8abb1dfd3ca50cda/resolv.conf",
027)         "HostnamePath": "/var/lib/docker/containers/1bb3c9ee963de0e8e54f2c232860def17ca6ac9e57a1a80b8abb1dfd3ca50cda/hostname",
028)         "HostsPath": "/var/lib/docker/containers/1bb3c9ee963de0e8e54f2c232860def17ca6ac9e57a1a80b8abb1dfd3ca50cda/hosts",
029)         "LogPath": "/var/lib/docker/containers/1bb3c9ee963de0e8e54f2c232860def17ca6ac9e57a1a80b8abb1dfd3ca50cda/1bb3c9ee963de0e8e54f2c232860def17ca6ac9e57a1a80b8abb1dfd3ca50cda-json.log",
030)         "Name": "/MD3-PROD",
031)         "RestartCount": 0,
032)         "Driver": "overlay2",
033)         "Platform": "linux",
034)         "MountLabel": "",
035)         "ProcessLabel": "",
036)         "AppArmorProfile": "",
037)         "ExecIDs": null,
038)         "HostConfig": {
039)             "Binds": [],
040)             "ContainerIDFile": "",
041)             "LogConfig": {
042)                 "Type": "json-file",
043)                 "Config": {}
044)             },
045)             "NetworkMode": "default",
046)             "PortBindings": {
047)                 "3000/tcp": [
048)                     {
049)                         "HostIp": "0.0.0.0",
050)                         "HostPort": "3700"
051)                     }
052)                 ]
053)             },
054)             "RestartPolicy": {
055)                 "Name": "",
056)                 "MaximumRetryCount": 0
057)             },
058)             "AutoRemove": false,
059)             "VolumeDriver": "",
060)             "VolumesFrom": null,
061)             "ConsoleSize": [
062)                 0,
063)                 0
064)             ],
065)             "CapAdd": null,
066)             "CapDrop": null,
067)             "CgroupnsMode": "private",
068)             "Dns": [],
069)             "DnsOptions": [],
070)             "DnsSearch": [],
071)             "ExtraHosts": null,
072)             "GroupAdd": null,
073)             "IpcMode": "private",
074)             "Cgroup": "",
075)             "Links": null,
076)             "OomScoreAdj": 0,
077)             "PidMode": "",
078)             "Privileged": false,
079)             "PublishAllPorts": false,
080)             "ReadonlyRootfs": false,
081)             "SecurityOpt": null,
082)             "UTSMode": "",
083)             "UsernsMode": "",
084)             "ShmSize": 67108864,
085)             "Runtime": "runc",
086)             "Isolation": "",
087)             "CpuShares": 0,
088)             "Memory": 0,
089)             "NanoCpus": 0,
090)             "CgroupParent": "",
091)             "BlkioWeight": 0,
092)             "BlkioWeightDevice": null,
093)             "BlkioDeviceReadBps": null,
094)             "BlkioDeviceWriteBps": null,
095)             "BlkioDeviceReadIOps": null,
096)             "BlkioDeviceWriteIOps": null,
097)             "CpuPeriod": 0,
098)             "CpuQuota": 0,
099)             "CpuRealtimePeriod": 0,
100)             "CpuRealtimeRuntime": 0,
101)             "CpusetCpus": "",
102)             "CpusetMems": "",
103)             "Devices": null,
104)             "DeviceCgroupRules": null,
105)             "DeviceRequests": null,
106)             "MemoryReservation": 0,
107)             "MemorySwap": 0,
108)             "MemorySwappiness": null,
109)             "OomKillDisable": null,
110)             "PidsLimit": null,
111)             "Ulimits": null,
112)             "CpuCount": 0,
113)             "CpuPercent": 0,
114)             "IOMaximumIOps": 0,
115)             "IOMaximumBandwidth": 0,
116)             "MaskedPaths": [
117)                 "/proc/asound",
118)                 "/proc/acpi",
119)                 "/proc/kcore",
120)                 "/proc/keys",
121)                 "/proc/latency_stats",
122)                 "/proc/timer_list",
123)                 "/proc/timer_stats",
124)                 "/proc/sched_debug",
125)                 "/proc/scsi",
126)                 "/sys/firmware"
127)             ],
128)             "ReadonlyPaths": [
129)                 "/proc/bus",
130)                 "/proc/fs",
131)                 "/proc/irq",
132)                 "/proc/sys",
133)                 "/proc/sysrq-trigger"
134)             ]
135)         },
136)         "GraphDriver": {
137)             "Data": {
138)                 "LowerDir": "/var/lib/docker/overlay2/8e6c824676bb548afecbe2e68f28424d803ec1e74294bf4d4cc7ed9bab62aa2e-init/diff:/var/lib/docker/overlay2/sl5cn1fmbagcwlhgohwmpx6vb/diff:/var/lib/docker/overlay2/is6pffv9osu45nk3tfgocwc2f/diff:/var/lib/docker/overlay2/et0r7i6k2kybxvkrczpoxjcq0/diff:/var/lib/docker/overlay2/pbe536rfpb6whcoesxwjv9tbh/diff:/var/lib/docker/overlay2/9qvznxjm8jrb3pb3h5fr7cpty/diff:/var/lib/docker/overlay2/f3cc87dc652c5628cffbb9cdff339dc929b50b1b31ec0f9099cddb5f4fe651d6/diff:/var/lib/docker/overlay2/0322675275fa827687e7a7c419df0d96876b4445a581d7db0a6c0a0f676856f1/diff:/var/lib/docker/overlay2/5ec5df3458cfd0df25c82a7da46c7e7c88dab0e697d9c28139c1667f6ea0c565/diff:/var/lib/docker/overlay2/5979711a75fc355ec595988391583e95c7e97d46d69f43f3a4aae980f5c12c49/diff",
139)                 "MergedDir": "/var/lib/docker/overlay2/8e6c824676bb548afecbe2e68f28424d803ec1e74294bf4d4cc7ed9bab62aa2e/merged",
140)                 "UpperDir": "/var/lib/docker/overlay2/8e6c824676bb548afecbe2e68f28424d803ec1e74294bf4d4cc7ed9bab62aa2e/diff",
141)                 "WorkDir": "/var/lib/docker/overlay2/8e6c824676bb548afecbe2e68f28424d803ec1e74294bf4d4cc7ed9bab62aa2e/work"
142)             },
143)             "Name": "overlay2"
144)         },
145)         "Mounts": [],
146)         "Config": {
147)             "Hostname": "1bb3c9ee963d",
148)             "Domainname": "",
149)             "User": "",
150)             "AttachStdin": false,
151)             "AttachStdout": false,
152)             "AttachStderr": false,
153)             "ExposedPorts": {
154)                 "3000/tcp": {}
155)             },
156)             "Tty": false,
157)             "OpenStdin": false,
158)             "StdinOnce": false,
159)             "Env": [
160)                 "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
161)                 "NODE_VERSION=16.20.0",
162)                 "YARN_VERSION=1.22.19",
163)                 "NODE_ENV=production"
164)             ],
165)             "Cmd": [
166)                 "npm",
167)                 "run",
168)                 "start"
169)             ],
170)             "Image": "md3-prod:latest",
171)             "Volumes": null,
172)             "WorkingDir": "/usr/src/app",
173)             "Entrypoint": [
174)                 "docker-entrypoint.sh"
175)             ],
176)             "OnBuild": null,
177)             "Labels": {}
178)         },
179)         "NetworkSettings": {
180)             "Bridge": "",
181)             "SandboxID": "cfe7b820a0ea0555a2fa04b55a26dacbaaf896767561d6b1a2544869b1455b79",
182)             "HairpinMode": false,
183)             "LinkLocalIPv6Address": "",
184)             "LinkLocalIPv6PrefixLen": 0,
185)             "Ports": {
186)                 "3000/tcp": [
187)                     {
188)                         "HostIp": "0.0.0.0",
189)                         "HostPort": "3700"
190)                     }
191)                 ]
192)             },
193)             "SandboxKey": "/var/run/docker/netns/cfe7b820a0ea",
194)             "SecondaryIPAddresses": null,
195)             "SecondaryIPv6Addresses": null,
196)             "EndpointID": "00aa18950608686183831931c0e11e5417bec0645272b040f9051fcffbf4955a",
197)             "Gateway": "172.17.0.1",
198)             "GlobalIPv6Address": "",
199)             "GlobalIPv6PrefixLen": 0,
200)             "IPAddress": "172.17.0.2",
201)             "IPPrefixLen": 16,
202)             "IPv6Gateway": "",
203)             "MacAddress": "02:42:ac:11:00:02",
204)             "Networks": {
205)                 "bridge": {
206)                     "IPAMConfig": null,
207)                     "Links": null,
208)                     "Aliases": null,
209)                     "NetworkID": "b33d63ddaa2cd83cbdd6cae4f2b1815ca7a4a4222c52c9d32c02698ba2549681",
210)                     "EndpointID": "00aa18950608686183831931c0e11e5417bec0645272b040f9051fcffbf4955a",
211)                     "Gateway": "172.17.0.1",
212)                     "IPAddress": "172.17.0.2",
213)                     "IPPrefixLen": 16,
214)                     "IPv6Gateway": "",
215)                     "GlobalIPv6Address": "",
216)                     "GlobalIPv6PrefixLen": 0,
217)                     "MacAddress": "02:42:ac:11:00:02",
218)                     "DriverOpts": null
219)                 }
220)             }
221)         }
222)     }
223) ]

links

social