title: Run a command as root with docker-compose in 2020?
body: <p>While in the process of painstakingly sculpting a Dockerfile and docker-compose.yml, what is <strong>THE RIGHT WAY</strong> to run root shell in work-in-progress containers (without actually starting their services!) in order to debug issues? I need to be able to run the shell as root, because only root has full access to files containing the information that I need to examine.</p>
  
  <p>I <strong>can</strong> modify Dockerfile and docker-compose.yml in order to achieve this goal; as I wrote above, I am in the process of sculpting those anyway.</p>
  
  <p>The problem however is that about the only way I can think of is putting <code>USER root</code> in Dockerfile or <code>user: root</code> in docker-compose.yml, but those SimplyHaveNoEffect™ in the <code>docker-compose run &lt;service&gt; bash</code> scenario. <code>whoami</code> in the shell thus started says <code>neo4j</code> instead of <code>root</code>, no matter what I try.</p>
  
  <p>I <strong>might</strong> add <code>sudo</code> to the image, which doesn't have <code>sudo</code>, but this should be considered <strong>last resort</strong>. Also using docker directly instead of docker-compose is less than preferable.</p>