# Copy localhost's ~/.kube/config file into the container and swap out localhost
# for host.docker.internal whenever a new shell starts to keep them in sync.
RUN echo '\n\
if [ "$SYNC_LOCALHOST_KUBECONFIG" == "true" ]; then\n\
mkdir -p $HOME/.kube\n\
cp -r $HOME/.kube-localhost/* $HOME/.kube\n\
sed -i -e "s/localhost/host.docker.internal/g" $HOME/.kube/config\n\
\n\
fi' \
if [ "$SYNC_LOCALHOST_GCLOUD" == "true" ]; then\n\
mkdir -p $HOME/.config/gcloud\n\
cp -r $HOME/.gcloud-localhost/* $HOME/.config/gcloud\n\
\n\
fi' \
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-11。"],[[["\u003cp\u003eThis guide outlines how to use Cloud Code for VS Code with Remote Development, enabling the building, debugging, and deployment of applications within a portable remote container.\u003c/p\u003e\n"],["\u003cp\u003eSetting up involves configuring a \u003ccode\u003e.devcontainer\u003c/code\u003e folder with a Dockerfile and \u003ccode\u003eDevcontainer.json\u003c/code\u003e file, tailored to your development language, to define the container's environment.\u003c/p\u003e\n"],["\u003cp\u003eThe Dockerfile should include instructions for installing the Google Cloud CLI and Skaffold, essential tools for working with Cloud Code, which you can add by following the official installation guides.\u003c/p\u003e\n"],["\u003cp\u003eThe process involves copying gcloud CLI and Skaffold configurations from the local host into the container, or rewriting the commands, to synchronize and maintain consistent settings between environments.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eDevcontainer.json\u003c/code\u003e file manages the container's settings like exposed ports and extensions, with an example provided that includes the installation of the Cloud Code extension.\u003c/p\u003e\n"]]],[],null,["# Develop a Kubernetes app with remote development\n\n\u003cbr /\u003e\n\nThis page explains how to use Cloud Code for VS Code\n[Remote Development](https://code.visualstudio.com/docs/remote/ssh),\nthat is, to open your codebase in a remote container where your application is\nbuilt, debugged, and deployed. This creates an application that's portable,\nregardless of the OS of your development machine.\n| **Note:** For steps to set up remote debugging on Chrome OS, see [Build a dev workflow with Cloud Code on a Pixelbook](/blog/products/application-development/build-a-dev-workflow-with-cloud-code-on-a-pixelbook).\n\nPrerequisites\n-------------\n\nIn addition to the setup described in\n[Install the Cloud Code extension](/code/docs/vscode/install),\ninstall the\n[Remote Development](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack)\nVS Code extension pack.\n\nSetup\n-----\n\n1. To set up a `.devcontainer` folder with a Dockerfile and `Devcontainer.json`\n file configured for the language you're using, click\n **Open a Remote Window** \\\u003e **Add Dev Container Config Files** .\n Alternatively, you can follow the steps in\n [Remote development in Containers](https://code.visualstudio.com/docs/remote/containers-tutorial).\n\n After you follow the prompts, your workspace will include:\n - Dockerfile --- defines a container image that holds the developer tools to\n install in a remote development container.\n\n - `Devcontainer.json` --- Instructs the VS Code Remote Tools extension how to run\n the remote development container.\n\n2. Open the Dockerfile and add instructions to install the\n [Google Cloud CLI](/sdk/docs/downloads-interactive) and\n [Skaffold](https://skaffold.dev/docs/install/). For up-to-date\n commands, see the installation guides.\n\n3. In the Dockerfile, add instructions to copy localhost's\n gcloud CLI and Skaffold configs before the `\u003e\u003e $HOME/.bashrc`\n command. Alternatively,\n you can rewrite the commands to install the gcloud CLI\n and Skaffold.\n\n # Copy localhost's ~/.kube/config file into the container and swap out localhost\n # for host.docker.internal whenever a new shell starts to keep them in sync.\n RUN echo '\\n\\\n if [ \"$SYNC_LOCALHOST_KUBECONFIG\" == \"true\" ]; then\\n\\\n mkdir -p $HOME/.kube\\n\\\n cp -r $HOME/.kube-localhost/* $HOME/.kube\\n\\\n sed -i -e \"s/localhost/host.docker.internal/g\" $HOME/.kube/config\\n\\\n \\n\\\n fi' \\\n if [ \"$SYNC_LOCALHOST_GCLOUD\" == \"true\" ]; then\\n\\\n mkdir -p $HOME/.config/gcloud\\n\\\n cp -r $HOME/.gcloud-localhost/* $HOME/.config/gcloud\\n\\\n \\n\\\n fi' \\\n\n4. Open the `Devcontainer.json` file and add the following run arguments to\n copy the gcloud CLI and Skaffold configs from localhost:\n\n \"-e\", \"SYNC_LOCALHOST_KUBECONFIG=true\",\n \"-e\", \"SYNC_LOCALHOST_GCLOUD=true\",\n\n5. After your files have the required contents, click\n\n **Open a Remote Window**.\n\nSample devcontainer.json file\n-----------------------------\n\nThe `devcontainer.json` file tells the Remote Container extension which ports to\nexpose in the container, how to mount drives, and which extensions to install\nin the remote container. The following sample `devcontainer.json` file\nspecifies that the Remote Container extension should install the\nCloud Code for VS Code extension: \n\n \"runArgs\": [\n \"-v\",\"/var/run/docker.sock:/var/run/docker.sock\",\n \"--mount\", \"type=bind,source=${env:HOME}${env:USERPROFILE}/.kube,target=/root/.kube-localhost\",\n \"--mount\", \"type=bind,source=${env:HOME}${env:USERPROFILE}/.config/gcloud,target=/root/.gcloud-localhost\",\n \"-e\", \"SYNC_LOCALHOST_KUBECONFIG=true\",\n \"-e\", \"SYNC_LOCALHOST_GCLOUD=true\",\n \"--cap-add=SYS_PTRACE\", \"--security-opt\", \"seccomp=unconfined\"\n ]\n\nWhat's next\n-----------\n\n- Read the Visual Studio docs on [remote development using SSH](https://code.visualstudio.com/docs/remote/ssh).\n- Take a tutorial to [run Visual Studio Code in a docker container](https://code.visualstudio.com/docs/devcontainers/tutorial). using the Dev containers extension.\n\nGet Support\n-----------\n\nTo send feedback, report issues on [GitHub](https://github.com/GoogleCloudPlatform/cloud-code-vscode/issues), or ask a question on [Stack Overflow](https://stackoverflow.com/questions/ask?tags=cloud-code-vscode)."]]