DOCKER RUN AS ROOT DOCKERFILE INSTALL
I don't have root privileges and when I need to install something, I do sudo apt-get install and enter my password to give me su access.įor my project, I'm trying to test install scripts as a regular user and thus these scripts use sudo and variables such as $HOME a lot ( $HOME for root is /root). For example, on my machine, I am the USER=emmanuel. Well if you're using docker in CI and need to test certain commands being run as a regular user then this is the way. Now you may be asking, why would someone want to do this? NB: You can add & echo 'pa55w0rd' | chpasswd right after the useradd to set a password.įor my use case, I need the password disabled and I need to NOT be prompted for a password when using sudo command. This will create a newuser without root privileges to run commands in the container. This can be changed by creating a new user in a Dockerfile by:Įnter fullscreen mode Exit fullscreen mode By default, most docker images, including ubuntu:latest have USER set to root. This is trivial and actually quite common in Dockerfiles. But to appropriately test my program, I would need to be a non-root user inside the docker container. This is fine for most intent and purposes. Most docker images use user root to execute commands. I want to release this program as an open source tool and for that reason it needs testing and CI. This is to allow me to reproduce my dev environment as fast as possible on a new Ubuntu installation.
DOCKER RUN AS ROOT DOCKERFILE SOFTWARE
Recently I wrote a pure bash menu program that has install scripts for various Ubuntu software I use. I have a particular use case that justifies this usage. Note that inside the current php images, it appears that the volume has been removed, which means we effectively have option 3.WARNING: This is generally considered NOT SECURE and thus do not use the methods in this article in a production container.
Create a temporary container using the image definition as of the current point of the dockerfile.
When a volume is defined in the Dockerfile, you can add files with a COPY or ADD command directly into the image. This issue is likely the result of a VOLUME definition inside the upstream Dockerfile. Running chmod same commands with bash inside the container: permissions are changed and my app is runningĪny idea, Am I missing something, maybe I should add root user somewhere in the Dockerfile ? Running chmod commands from dockerfile: permissions are changed but apache still complains about permission denied. and when I run chmod from container's bash, apache permission issues are gone and the app works well and run the container with docker run -p 8080:80 myname/symfony_apps:latest.Īpache log is flooded by permission denied errors, the strange thing that I've checked with ls -a and permissions are fine.
When I build this image with docker build -t myname/symfony_apps:latest. RUN chmod -R 777 /var/www/html/app/cache /var/www/html/app/logs RUN find /var/www/html/ -type d -exec chmod 755 \ & docker-php-ext-install intl mbstring \ĬOPY app/nf /etc/apache2/nf & apt-get install -y libicu-dev freetds-common freetds-bin unixodbc \ I'm building a Docker image for my Symfony app and I need to give permission to apache server to write into cache and log folders #Dockerfile