Skip to content

Commit d14f9a3

Browse files
committed
Run Docker container with a specific user.
Pass --user (`DOCKER_USER`) attribute when creating the container. This has no effect in production since we are using the same user and group than the one defined inside the Dockerfile image (docs:docs). Although, this allow us to avoid permissions conflicts when running the build with Docker locally (development) since we can pass our current user. That way, every file created/modified inside the container will be done using the current UID and GID defined by the developer. This can be done as, local_settings.py DOCKER_USER = f'{os.geteuid()}:{os.getegid()}' With this change, there is no need to re-build the Docker image used in production with our own custom `USER` instruction. https://docs.docker.com/engine/reference/run/#user
1 parent 5f78337 commit d14f9a3

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

readthedocs/doc_builder/environments.py

+1
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,7 @@ def create_container(self):
10251025
host_config=self.get_container_host_config(),
10261026
detach=True,
10271027
environment=self.environment,
1028+
user=settings.DOCKER_USER,
10281029
)
10291030
client.start(container=self.container_id)
10301031
except ConnectionError:

readthedocs/settings/base.py

+9
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,15 @@ def USE_PROMOS(self): # noqa
276276

277277
# Docker
278278
DOCKER_ENABLE = False
279+
280+
# User used to create the container.
281+
# In production we use the same user than the one defined by the
282+
# ``USER docs`` instruction inside the Dockerfile.
283+
# In development, we can use the "UID:GID" of the current user running the
284+
# instance to avoid file permissions issues.
285+
# https://docs.docker.com/engine/reference/run/#user
286+
DOCKER_USER = 'docs:docs'
287+
279288
DOCKER_DEFAULT_IMAGE = 'readthedocs/build'
280289
DOCKER_DEFAULT_VERSION = 'latest'
281290
DOCKER_IMAGE = '{}:{}'.format(DOCKER_DEFAULT_IMAGE, DOCKER_DEFAULT_VERSION)

0 commit comments

Comments
 (0)