PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label codespaces. Show all posts
Showing posts with label codespaces. Show all posts

Tuesday, October 18, 2022

[FIXED] How do I mount a Codespace's workspace in a Docker container?

 October 18, 2022     codespaces, docker     No comments   

Issue

When I try to mount the workspace directory in a Codespace in a Docker container (with -v), the mounted path is empty, e.g:

$ ls /workspaces/myrepo
[list of files]

$ docker run -it --rm -v /workspaces/myrepo:/app alpine:latest

/ # ls /app
[nothing]

Solution

I believe this is because the Codespace is itself running in Docker, and so the mount points are relative to the Docker host (of the Codespace), not to the container in which the Codespace is running.


One solution is to use --volumes-from to remount the volumes for the Codespace (e.g. /workspaces/myrepo) inside the container you are starting. This requires knowing the container ID of the container in which the Codespace is running, which we can obtain with docker ps --filter "label=Type=codespaces".

As a bonus --workdir can also be used to start the container in the current directory.

Putting it together:

$ docker run -it --rm --volumes-from $(docker ps --filter "label=Type=codespaces" -q) --workdir $(pwd) alpine:latest

/workspaces/myrepo/ # ls .
[list of files]


Answered By - davetapley
Answer Checked By - Timothy Miller (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home
View mobile version

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing