devcontainers / templates

Repository for Dev Container Templates that are managed by Dev Container spec maintainers. See https://github.com/devcontainers/template-starter to create your own!
https://containers.dev/templates
MIT License
1.01k stars 259 forks source link

how to properly use apt-get for dev container? #264

Open KriachkoAS opened 5 months ago

KriachkoAS commented 5 months ago

I currently use devcontainer.json with

FROM mcr.microsoft.com/devcontainers/python:1-3.10-buster
#FROM python:3.10-slim

USER root

#RUN sudo apt-get update# \
#  && apt-get -y install tesseract-ocr \ # required for pytesseract

as Dockerfile. Every time i uncomment RUN sudo apt-get update dev container is staring with exception. What may be appropriate solution? Exception:

[2024-06-13T17:14:16.780Z] Stop (5071 ms): Run: docker buildx build --load --build-arg BUILDKIT_INLINE_CACHE=1 -f C:\Users\faQ\AppData\Local\Temp\devcontainercli\container-features\0.62.0-1718298849701\Dockerfile-with-features -t vsc-meduzzen_cv_internship-5423384e0a528bb79615ca79de36d2f7ec3f7bcdedd85db936ad2e8fb325b818 --target dev_containers_target_stage --build-context dev_containers_feature_content_source=C:\Users\faQ\AppData\Local\Temp\devcontainercli\container-features\0.62.0-1718298849701 --build-arg _DEV_CONTAINERS_BASE_IMAGE=dev_container_auto_added_stage_label --build-arg _DEV_CONTAINERS_IMAGE_USER=root --build-arg _DEV_CONTAINERS_FEATURE_CONTENT_SOURCE=dev_container_feature_content_temp p:\projects\programming\ds\cv\meduzzen_cv_internship\.devcontainer
[2024-06-13T17:14:16.781Z] Error: Command failed: docker buildx build --load --build-arg BUILDKIT_INLINE_CACHE=1 -f C:\Users\faQ\AppData\Local\Temp\devcontainercli\container-features\0.62.0-1718298849701\Dockerfile-with-features -t vsc-meduzzen_cv_internship-5423384e0a528bb79615ca79de36d2f7ec3f7bcdedd85db936ad2e8fb325b818 --target dev_containers_target_stage --build-context dev_containers_feature_content_source=C:\Users\faQ\AppData\Local\Temp\devcontainercli\container-features\0.62.0-1718298849701 --build-arg _DEV_CONTAINERS_BASE_IMAGE=dev_container_auto_added_stage_label --build-arg _DEV_CONTAINERS_IMAGE_USER=root --build-arg _DEV_CONTAINERS_FEATURE_CONTENT_SOURCE=dev_container_feature_content_temp p:\projects\programming\ds\cv\meduzzen_cv_internship\.devcontainer
[2024-06-13T17:14:16.782Z]     at mtA (c:\Users\faQ\.vscode\extensions\ms-vscode-remote.remote-containers-0.369.0\dist\spec-node\devContainersSpecCLI.js:465:1933)
[2024-06-13T17:14:16.782Z]     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[2024-06-13T17:14:16.782Z]     at async Pm (c:\Users\faQ\.vscode\extensions\ms-vscode-remote.remote-containers-0.369.0\dist\spec-node\devContainersSpecCLI.js:464:1841)
[2024-06-13T17:14:16.782Z]     at async NH (c:\Users\faQ\.vscode\extensions\ms-vscode-remote.remote-containers-0.369.0\dist\spec-node\devContainersSpecCLI.js:464:610)
[2024-06-13T17:14:16.782Z]     at async KtA (c:\Users\faQ\.vscode\extensions\ms-vscode-remote.remote-containers-0.369.0\dist\spec-node\devContainersSpecCLI.js:481:3692)
[2024-06-13T17:14:16.782Z]     at async eB (c:\Users\faQ\.vscode\extensions\ms-vscode-remote.remote-containers-0.369.0\dist\spec-node\devContainersSpecCLI.js:481:4807)
[2024-06-13T17:14:16.783Z]     at async hrA (c:\Users\faQ\.vscode\extensions\ms-vscode-remote.remote-containers-0.369.0\dist\spec-node\devContainersSpecCLI.js:661:13373)
[2024-06-13T17:14:16.783Z]     at async lrA (c:\Users\faQ\.vscode\extensions\ms-vscode-remote.remote-containers-0.369.0\dist\spec-node\devContainersSpecCLI.js:661:13114)
[2024-06-13T17:14:16.799Z] Stop (8648 ms): Run: P:\soft\programming\Microsoft VS Code\Code.exe c:\Users\faQ\.vscode\extensions\ms-vscode-remote.remote-containers-0.369.0\dist\spec-node\devContainersSpecCLI.js up --user-data-folder c:\Users\faQ\AppData\Roaming\Code\User\globalStorage\ms-vscode-remote.remote-containers\data --container-session-data-folder /tmp/devcontainers-7c420d15-3339-43ce-bb22-c54f635d28b31718298842474 --workspace-folder p:\projects\programming\ds\cv\meduzzen_cv_internship --workspace-mount-consistency cached --id-label devcontainer.local_folder=p:\projects\programming\ds\cv\meduzzen_cv_internship --id-label devcontainer.config_file=p:\projects\programming\ds\cv\meduzzen_cv_internship\.devcontainer\devcontainer.json --log-level debug --log-format json --config p:\projects\programming\ds\cv\meduzzen_cv_internship\.devcontainer\devcontainer.json --default-user-env-probe loginInteractiveShell --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root
[2024-06-13T17:14:16.800Z] Exit code 1
[2024-06-13T17:14:16.806Z] Command failed: P:\soft\programming\Microsoft VS Code\Code.exe c:\Users\faQ\.vscode\extensions\ms-vscode-remote.remote-containers-0.369.0\dist\spec-node\devContainersSpecCLI.js up --user-data-folder c:\Users\faQ\AppData\Roaming\Code\User\globalStorage\ms-vscode-remote.remote-containers\data --container-session-data-folder /tmp/devcontainers-7c420d15-3339-43ce-bb22-c54f635d28b31718298842474 --workspace-folder p:\projects\programming\ds\cv\meduzzen_cv_internship --workspace-mount-consistency cached --id-label devcontainer.local_folder=p:\projects\programming\ds\cv\meduzzen_cv_internship --id-label devcontainer.config_file=p:\projects\programming\ds\cv\meduzzen_cv_internship\.devcontainer\devcontainer.json --log-level debug --log-format json --config p:\projects\programming\ds\cv\meduzzen_cv_internship\.devcontainer\devcontainer.json --default-user-env-probe loginInteractiveShell --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root
[2024-06-13T17:14:16.806Z] Exit code 1
samruddhikhandale commented 4 months ago

The exception you're encountering when uncommenting the RUN sudo apt-get update line in your Dockerfile seems to be related to the Docker build process rather than the specific command itself. The error log indicates a failure during the build process but doesn't provide a clear reason why the apt-get update command would cause it to fail.

Here are a few steps to troubleshoot and potentially resolve the issue:

Syntax Check: Ensure there are no syntax errors in your Dockerfile. The commented-out lines should be correctly uncommented, and there should be no trailing spaces or characters. The correct syntax for the command should be:

RUN apt-get update && apt-get -y install tesseract-ocr

Note that you don't need sudo in Dockerfiles because commands run as the root user by default.

Docker Build Context: The error log mentions paths and build contexts that seem specific to your setup. Ensure that the build context (the path you're providing to Docker when you start the build, typically . for the current directory) is correct and that all necessary files are accessible.

BuildKit: The log mentions docker buildx which uses Docker's BuildKit. BuildKit sometimes behaves differently than the traditional Docker build. You can try disabling BuildKit to see if that affects the outcome. Set the environment variable DOCKER_BUILDKIT=0 and run the build again.

Clear Docker Cache: Sometimes, Docker's cache can cause issues. You can try building the image without cache by adding --no-cache to your Docker build command to see if that resolves the issue.

Check for External Issues: Sometimes, network issues or external changes (like updated base images or package repositories) can temporarily break builds. Verify that you can run apt-get update successfully in a simple Docker container based on the same image.

If after these steps the issue persists, consider isolating the problem by creating a minimal Dockerfile that only runs the apt-get update command. This can help determine if the issue is with the Docker setup or something specific to your project's configuration.