Help with remote dev container #133
-
I just joined a team that is using docker containers. I've never used containers before. I'm trying to figure out how to best incorporate vscode into our container setup/process. The guy on our team that has setup our dev container provided a means to run the container, then attach locally in a terminal. I've been trying to figure out how to use vscode to attach to the container. I've found a process that works for me but it's cumbersome.
I played around some with a devcontainer.json file. This seems to be a more streamlined way to go.. however, I ran into a number of problems. The primary problem being that our script to run/connect to the container does a number of operations after the container has been started (ex 'docker exec adduser ...', 'docker cp ', etc). Is there a way to configure devcontainer.json to run the 'start container' script we already have, then just connect to the container? If that's not possible, is there a way to issue 'docker exec/cp/etc' commands after vscode has started the docker? Whenever I would run with a devcontainer.json the process would fail because no user had been setup yet. Thanks for any help. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi 👋 Welcome to the Dev Container community. You can configure the Please note that the script file should be in a location that is accessible to the container. You can add the script file to your project and use a relative path to it in the devcontainer.json file. Also, keep in mind that these commands run inside the container, not on the host machine. If you need to run commands on the host machine, you might need to adjust your setup or script accordingly. |
Beta Was this translation helpful? Give feedback.
Hi 👋
Welcome to the Dev Container community.
Have you looked at https://containers.dev/implementors/json_reference/#lifecycle-scripts document?
You can configure the
devcontainer.json
file to run a lifecycle script after the container has started. You can use thepostCreateCommand
orpostStartCommand
properties in thedevcontainer.json
file to run commands after the container has been created or started, respectively.Please note that the script file should be in a location that is accessible to the container. You can add the script file to your project and use a relative path to it in the devcontainer.json file.
Also, keep in mind that these commands run inside the container, not on the …