I have a dockerized Django application (Dockerfile + docker-compose.yml in project root).
I have three services:
nginxpostgresdjango
I'm trying to use VScode with the Remote-Containers extension, so what I have right now is a .devcontainer directory with two files (this was setup automatically):
devcontainer.jsondocker-compose.yml(yes, another one apart from the one in the project root)
Here's the issue. I open vscode and I choose Reopen in Container option. This brings up all the services just fine. The thing is any time I create a file via vscode or using bash inside the container, it gets created with owner root. This is because root is the default user for the django container.
I looked into possible solutions, but I can only find ones involving adding a non-root user in the Dockerfile. I am not the maintainer of the Dockerfile so, I don't wanna do this. I am not the maintainer of the docker-compose.yml either but I figure this is ok to change. I can always just stash my changes and pop them if there's any change to this particular file.
Having that in mind, I edited the docker-compose.yml and added the line user: "${HOST_USER}" to my django container (HOST_USER is an env variable that evaluates to 1000:1000) but then I get permission errors:
All I want is to be able to use django container as my dev environment without having to worry about file permissions. Is maybe the Dockerfile inside the .devcontainer directory the way to go? If so, what would I have to add?
.devcontainer/devcontainer.json:
{
"name": "Existing Docker Compose (Extend)",
"dockerComposeFile": [
"../docker-compose.yml",
"docker-compose.yml"
],
"service": "django",
"workspaceFolder": "/workspace",
"settings": {},
"extensions": [
"ms-python.python"
]
}
.devcontainer/docker-compose.yml:
version: '3.0'
services:
django:
# Uncomment if you want to override the service's Dockerfile to one in the .devcontainer
# folder. Note that the path of the Dockerfile and context is relative to the *primary*
# docker-compose.yml file (the first in the devcontainer.json "dockerComposeFile"
# array). The sample below assumes your primary file is in the root of your project.
#
# build:
# context: .
# dockerfile: .devcontainer/Dockerfile (MAYBE THIS SOLVES THE ISSUE?)
volumes:
- .:/workspace
command: /bin/sh -c "while sleep 1000; do :; done"
