Skip to content

Latest commit

 

History

History
40 lines (31 loc) · 1.27 KB

Mount_Home_Directory.md

File metadata and controls

40 lines (31 loc) · 1.27 KB

When using a devcontainer you often want personal settings like global git configuration, ssh keys, bash history, etc. to be maintained regardless of the container image. By default, when a new container image is used, the home directory is not preserved. This can be mitigated by mounting a persistent volume to be used as the home directory.

Here are the steps to enable this:

  1. Using Docker, create a linux $HOME directory volume.
docker volume create linux-home-dir
  1. Open the devcontainer using VSCode and in the terminal (in the container) run the following commands to determine the absolute path to the $HOME directory.
cd ~
pwd
# (Example result: "/opt/app-root/src")
  1. In VSCode, update your devcontainer.json file and add the following.
// The optional 'runArgs' property can be used to specify additional runtime arguments
 "runArgs": [
   // Mount home directory as a volume to preserve settings like .ssh and .gitconfig
   "-v",
   "linux-home-dir:/opt/app-root/src"
 ],
  1. In VSCode, run Ctrl+Shift+P Remote-Container: Rebuild Container.

  2. Your linux-home-dir volume will now be mounted as the $HOME directory of the container making it much more convenient to use between updates to the devcontainer image.