docker: Allow to call with USER_ID=0
When we run as root on the host and want to allow the builder to do the same, e.g. to access root-owned volumes, accept USER_ID=0 to express this. This allows to tell the user to call "docker run -e USER_ID=$(id -u)", and it will always reflect the calling context's permissions into the container. Reported-by: Jan Christian Grünhage <jan.christian@gruenhage.xyz> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
		
				
					committed by
					
						
						Daniel Wagner
					
				
			
			
				
	
			
			
			
						parent
						
							bb853cec02
						
					
				
				
					commit
					8d5ce95347
				
			@@ -13,13 +13,24 @@ fi
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
USER_ID=${USER_ID:-30000}
 | 
					USER_ID=${USER_ID:-30000}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Create a non-root user that will perform the actual build
 | 
					if [ $USER_ID == 0 ]; then
 | 
				
			||||||
id builder 2>/dev/null || \
 | 
						# We shall run everything as root
 | 
				
			||||||
    useradd --uid $USER_ID --create-home --home-dir /builder builder
 | 
						mkdir /builder
 | 
				
			||||||
 | 
					
 | 
				
			||||||
cd /builder
 | 
						cd /builder
 | 
				
			||||||
if [ -n "$1" ]; then
 | 
						if [ -n "$1" ]; then
 | 
				
			||||||
	exec gosu builder "$@"
 | 
							exec "$@"
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							exec bash
 | 
				
			||||||
 | 
						fi
 | 
				
			||||||
else
 | 
					else
 | 
				
			||||||
	exec gosu builder bash
 | 
						# Create a non-root user that will perform the actual build
 | 
				
			||||||
 | 
						useradd --uid $USER_ID --create-home --home-dir /builder builder
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						cd /builder
 | 
				
			||||||
 | 
						if [ -n "$1" ]; then
 | 
				
			||||||
 | 
							exec gosu builder "$@"
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							exec gosu builder bash
 | 
				
			||||||
 | 
						fi
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user