Compose shell access to sibling containers #113197
-
Select Topic AreaQuestion BodyWhen using codespaces with a Docker Compose file referenced in the devcontainer.json how do you access a shell on sibling containers? On a local workstation you can use "docker exec". Is there no built-in support for this? For example in order to view a log file in a database that is included in a sibling container. Maybe docker must be installed manually in the devcontainer (docker-in-docker?) If using a project without an explicit devcontainer I noticed the default devcontainer already has docker installed and can run docker-in-docker. Is this the preferred approach? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
When using codespaces with a Docker Compose file referenced in the devcontainer.json, accessing a shell on sibling containers can be achieved through a few different methods. One approach is to use the docker exec command directly within the codespace terminal. This allows you to execute commands within a running container. For example, to access a shell in a sibling container, you could run:
Replace <sibling_container_id> with the ID or name of the sibling container you want to access. Alternatively, if your Docker Compose setup includes services that you need to interact with frequently, you might consider configuring additional services directly within your devcontainer.json file. This allows you to define dependencies and configurations specific to your development environment. You can include additional Docker Compose services in the dockerComposeFile or dockerComposeFile services section of the devcontainer.json file. This approach can streamline development and provide easy access to sibling containers from within the codespace. As for the installation of Docker within the devcontainer, it depends on your project's requirements and preferences. If your project relies heavily on Docker, installing Docker within the devcontainer (docker-in-docker) can be a viable approach. This allows you to manage and interact with containers directly within the codespace environment. However, keep in mind that running Docker within Docker introduces some complexities and potential performance overhead. If your project does not explicitly require Docker, relying on the default devcontainer, which already has Docker installed and can run docker-in-docker, may be a convenient option. This allows you to leverage Docker capabilities without the need for manual installation or configuration. Evaluate your project's specific needs and consider the trade-offs associated with each approach to determine the best fit for your development workflow. |
Beta Was this translation helpful? Give feedback.
-
Seems like it may be safest to use Microsoft's own image when working with compose in codespaces so that you can use the "feature" of either:
There is a lot going on under the hood that is likely tricky to re-create in your own custom image. the
|
Beta Was this translation helpful? Give feedback.
-
🕒 Discussion Activity Reminder 🕒 This Discussion has been labeled as dormant by an automated system for having no activity in the last 60 days. Please consider one the following actions: 1️⃣ Close as Out of Date: If the topic is no longer relevant, close the Discussion as 2️⃣ Provide More Information: Share additional details or context — or let the community know if you've found a solution on your own. 3️⃣ Mark a Reply as Answer: If your question has been answered by a reply, mark the most helpful reply as the solution. Note: This dormant notification will only apply to Discussions with the Thank you for helping bring this Discussion to a resolution! 💬 |
Beta Was this translation helpful? Give feedback.
It sounds like "no" to built-in support in codespaces interface and "yes" to you must install docker inside the dev container, though default devcontainer has it already installed. It isn't clear if it's functioning in sibling mode (bind mounted /var/run/docker.sock) or true docker-in-docker. Either way, it doesn't appear Docker fully supports this: https://jpetazzo.github.io/2015/09/03/do-not-use-docker-in-docker-for-ci/. This appears to be a major obstacle for codespaces.
Generally the whole point of dev container is to provide a pre-built image containing the specific tools to build the project, which means the default container generally isn't going to cut it. So it sounds like the on…