在 VS Code 中使用 FrankenPHP 服务(取决于 Memcached 和 Postgres 服务)设置 Docker 开发容器,我了解到 Memcached 和 Postgres 服务启动并运行,并且主应用程序服务转储并出现一两个错误。
带有错误序列的 Docker 日志:
✔ Container newseeds_devcontainer-db-1 Running 0.0s
✔ Container newseeds_devcontainer-cache-1 Running 0.0s
✔ Container newseeds_devcontainer-app-1 Started 0.0s
[1292 ms] Start: Run: docker ps -q -a --filter label=com.docker.compose.project=newseeds_devcontainer --filter label=com.docker.compose.service=app
[1330 ms] Start: Run: docker inspect --type container 38bd8826df6d
[1442 ms] Start: Inspecting container
[1442 ms] Start: Run: docker inspect --type container 38bd8826df6d56722aa2b2b25d8f082630e1f7c2043e9c722135edd839838a7f
[1473 ms] Start: Run in container: /bin/sh
[1474 ms] Start: Run in container: uname -m
[1505 ms] Shell server terminated (code: 1, signal: null)
[1505 ms] Error response from daemon: container 38bd8826df6d56722aa2b2b25d8f082630e1f7c2043e9c722135edd839838a7f is not running
[1505 ms] Start: Run in container: (command -v getent >/dev/null 2>&1 && getent passwd 'root' || grep -E '^root|^[^:]*:[^:]*:root:' /etc/passwd || true)
[1505 ms] Stdin closed!
[1505 ms] Error: An error occurred setting up the container.
[1505 ms] at CtA (/Users/fpolli/.vscode/extensions/ms-vscode-remote.remote-containers-0.354.0/dist/spec-node/devContainersSpecCLI.js:409:3709)
[1505 ms] at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[1505 ms] at async UtA (/Users/fpolli/.vscode/extensions/ms-vscode-remote.remote-containers-0.354.0/dist/spec-node/devContainersSpecCLI.js:481:3865)
[1505 ms] at async $C (/Users/fpolli/.vscode/extensions/ms-vscode-remote.remote-containers-0.354.0/dist/spec-node/devContainersSpecCLI.js:481:4807)
[1505 ms] at async QrA (/Users/fpolli/.vscode/extensions/ms-vscode-remote.remote-containers-0.354.0/dist/spec-node/devContainersSpecCLI.js:661:13255)
[1505 ms] at async urA (/Users/fpolli/.vscode/extensions/ms-vscode-remote.remote-containers-0.354.0/dist/spec-node/devContainersSpecCLI.js:661:12996)
[1507 ms] Exit code 1
下面是 docker-compose 文件、应用程序容器的 dockerfile 和 devcontainers.json:
docker-compose:
services:
app:
build:
context: .
entrypoint: php artisan octane:frankenphp --max-requests=1
ports:
- "80:8000"
- "443:443"
depends_on:
- db
- cache
volumes:
- storage://D/www/laravel-projects/newseeds/storage
command: sleep infinity,
networks:
- storefront
- backroom
db:
image: postgres:latest
restart: unless-stopped
volumes:
- data://D/PostgreSQL/data
environment:
POSTGRES_USER: theuser
POSTGRES_DB: arandomname
POSTGRES_PASSWORD: "very ultra secret"
networks:
- backroom
cache:
image: memcached:latest
restart: unless-stopped
#volumes:
networks:
- backroom
networks:
storefront:
backroom:
volumes:
data:
storage:
Dockerfile:
FROM dunglas/frankenphp
RUN install-php-extensions pcntl
COPY . /app
ENTRYPOINT ["php", "artisan", "octane:frankenphp"]
devcontainer.json
"name": "the name",
"dockerComposeFile": "./docker-compose.yaml",
"service": "app",
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
"features": {
"ghcr.io/devcontainers/features/node:1": {
"nodeGypDependencies": true,
"version": "lts",
"nvmVersion": "latest"
},
},
"forwardPorts": [
5432
],
//"remoteUser": "root",
"customizations": {
"vscode": {
"extensions": [
"onecentlin.laravel5-snippets"
]
}
}
}
请注意,我在 Windows 11 PC 桌面和 MacBook 上进行开发,在 PC 上,需要激活“remoteUser”行才能读取 devcontainer.json 文件,在 MacBook 上,需要对其进行注释出去。我在 MacBook 上写了这篇文章,因此发表了评论。两台计算机上的结果是相同的。
谢谢你。
您的 docker 容器自行终止
[1505 ms] Error response from daemon: container 38bd8826df6d56722aa2b2b25d8f082630e1f7c2043e9c722135edd839838a7f is not running
原因未知,但可以是任何原因(错误或正常终止)。但显然 VSCode 在退出时无法继续连接到容器。
考虑在 docker compose 中设置“command: sleep infinity”或在 Dockerfile 中设置“CMD sleep infinity”。