Tectrendz
Tectrendz

Reputation: 1454

Running script configured in Dockerfile after starting container as root user

What is the right way to start a container as root user?

I am trying to run a script on container startup.

Following is the starting of the script.

#!/bin/sh

[ "$USER" = root ] || { echo "You must run $0 as root."; exit 1; }

Here are the contents of dockerfile.

USER root    
CMD "/service/run-dnscache.sh"

Command to build:

docker build --tag=friendlyhello --no-cache .

On running the container user seems to be non root. How do I run it as root?

vpp@VPP1:~/tmp$ docker run -it  --user root friendlyhello
You must run /service/run-dnscache.sh as root.


vpp@VPP1:~/tmp$ docker run -it  friendlyhello
You must run /service/run-dnscache.sh as root.

Upvotes: 0

Views: 209

Answers (1)

David J Eddy
David J Eddy

Reputation: 2037

What is the right way to start a container as root user?

The default user INSIDE a container IS root. Typically container via the Docker daemon are running as root on the host machine as well.

What happens when you $(whoami) inside the container on start?

Upvotes: 1

Related Questions