8

I'm currently working on a project which requires me to use a VSCode Remote Container. I have decided not to base my container on one of the official Microsoft images available here instead it is based on the epitechcontent/epitest-docker docker image.

I am using the following configuration for the container so far:

.devcontainer/devcontainer.json

{
    "name": "Babel",
    "build": {
        "dockerfile": "Dockerfile",
    },
    "runArgs": [
        "--cap-add=SYS_PTRACE",
        "--security-opt",
        "seccomp=unconfined"
    ],
    "extensions": [
        "ms-vscode.cpptools",
        "ms-vscode.cmake-tools",
        "twxs.cmake"
    ],
    "remoteUser": "babel",
    "workspaceMount": "type=bind,source=${localWorkspaceFolder},target=/home/babel"
}

.devcontainer/Dockerfile

# Using the latest epitech image
FROM epitechcontent/epitest-docker

# Setup a custom user with similar permissions
RUN useradd -rm -d /home/babel -s /bin/zsh -g root -G root -u 1001 babel

# Configure our workspace
WORKDIR /home/babel
RUN touch dummyfile

I am currently running into the following problems.

Container user permissions

It appears Microsoft VSCode Remote Containers create a default non-root user called vscode for all containers. As I'm not using the Microsoft images I'm looking for a way to create a user with the same permissions as my session so that files created in the container are identical to those created outside the container by my regular user.

To achieve this I'm creating a new user in the Dockerfile and I'm also setting the remoteUser property in the devcontainer.json to that very user.

What happens next is when I try to create a file inside the remote container it has different permissions than my regular session.

inside-the-container-shell> ls -l
-rw-rw-r-- 1 babel root     14 Sep 22 16:59 file-created-outside-container
-rw-r--r-- 1 babel root      0 Sep 22 19:27 file-created-inside-container

Workspace and mount location

Inside the Dockerfile I set my user's home directory to /home/babel and I set the WORKDIR to /home/babel as well. In addition, inside devcontainer.json I'm setting workspaceMount to type=bind,source=${localWorkspaceFolder},target=/home/babel so the container is mounted in the home directory of the user.

Unfortunately this overrides the dummyfile that was touched during the building stage (cf the Dockerfile).

Conclusion

I'm having a hard time finding good resources to learn how to use VSCode Remote Containers without the Microsoft images.

I'm trying to find a good way to declare a custom user much like the Microsoft images do.

I'm trying to find a way to not override the files that are here before the mount takes place.

Diego ROJAS
  • 509
  • 1
  • 7
  • 14
  • Did you manage to create own docker image? I am curious. Can you share the results? – Pierwiastek Aug 01 '22 at 09:44
  • I'm not sure I understand your question @Pierwiastek, are you asking if I managed to run a VSCode remote container with a custom built image? If so yes, and I'm happy to share the configuration with you. If you meant something else, let me know. – Diego ROJAS Aug 02 '22 at 10:22
  • Yes, indeed, I am interested if you managed to run a VSCode remote container build on custom image, I would be very grateful for sharing the Dockerfile or any hints :) – Pierwiastek Aug 03 '22 at 09:19
  • 1
    Sure @Pierwiastek ! [Here](https://gist.github.com/rojas-diego/fa3dd471db6275c387a5473fbf28e19d) is a link to a Github Gist which does this. It's from 10 months ago, I don't remember much of it but I hope it's what you're searching for. – Diego ROJAS Aug 09 '22 at 18:00
  • @DiegoROJAS - Have you find some documentation or reference for help? – xs2tarunkukreja Oct 21 '22 at 06:16

0 Answers0