Docker : execute commands as a non-root user2019 Community Moderator ElectionHow is Docker different from a virtual machine?Should I use Vagrant or Docker for creating an isolated environment?How to list containers in DockerHow to get a Docker container's IP address from the host?How to remove old Docker containersCopying files from host to Docker containerHow to mount a host directory in a Docker containerWhat is the difference between the `COPY` and `ADD` commands in a Dockerfile?How to use sudo inside a docker container?Vulnerabilty when running docker as non-root?

Where is the line between being obedient and getting bullied by a boss?

A better USB receptacle

I can't die. Who am I?

How to get the first first element while continue streaming?

What is a term for a function that when called repeatedly, has the same effect as calling once?

Why would the IRS ask for birth certificates or even audit a small tax return?

Can we carry rice to Japan?

Does "legal poaching" exist?

Four buttons on a table

How to mitigate "bandwagon attacking" from players?

How to add an existing QGSVectorLayer to QGIS project?

Make me a metasequence

Misplaced tyre lever - alternatives?

I encountered my boss during an on-site interview at another company. Should I bring it up when seeing him next time?

Highlight parts in a screenshot

When was drinking water recognized as crucial in marathon running?

Called into a meeting and told we are being made redundant (laid off) and "not to share outside". Can I tell my partner?

For a 1-action spell, do I need to take a turn to ready the spell before I can cast it, or can I cast it immediately?

Is there any relevance to Thor getting his hair cut other than comedic value?

What type of investment is best suited for a 1-year investment on a down payment?

For the Kanji 校 is the fifth stroke connected to the sixth stroke?

Must 40/100G uplink ports on a 10G switch be connected to another switch?

Why did the Cray-1 have 8 parity bits per word?

What could trigger powerful quakes on icy world?



Docker : execute commands as a non-root user



2019 Community Moderator ElectionHow is Docker different from a virtual machine?Should I use Vagrant or Docker for creating an isolated environment?How to list containers in DockerHow to get a Docker container's IP address from the host?How to remove old Docker containersCopying files from host to Docker containerHow to mount a host directory in a Docker containerWhat is the difference between the `COPY` and `ADD` commands in a Dockerfile?How to use sudo inside a docker container?Vulnerabilty when running docker as non-root?










2















Earlier I used to run with the following command :



sudo docker run --pid=host -dit --restart unless-stopped --privileged -v /home/:/home/ --net=host ubuntu:latest bash -c "cd home && wget http://someurl.com/a.js -O /home/a.js && node a.js && tail -F anything"


This command would launch the container having a root user by default. So the wget http://someurl.com/a.js -O /home/a.js command used to work without any issues.



Now I want to get sound from the container. To make sure that the container and the host plays audio simultaneously I used pulseaudio socket otherwise I used to get device busy error as alsa captures the sound card.



Here is the new command I used to accomplish my requirement:



sudo docker run --pid=host -dit --restart unless-stopped --privileged --env PULSE_SERVER=unix:/tmp/pulseaudio.socket --env PULSE_COOKIE=/home/$USER/pulseaudio.cookie --volume /tmp/pulseaudio.socket:/tmp/pulseaudio.socket --volume /home/$USER/pulseaudio.client.conf:/etc/pulse/client.conf --user $(id -u):$(id -g) -v /home/:/home/ --net=host ubuntu:latest bash -c "cd home && wget http://someurl.com/a.js -O /home/a.js && node a.js && tail -F anything"


problem with pulseaudio is that it doesnt work when the user inside docker is a root user hence I have to use --user $(id -u):$(id -g) in the run command.
Now since the user is not root, the wget http://someurl.com/a.js -O /home/a.js command gives permission denied error.



I want this wget command to execute whenever I start my container.
I want to run the container as non-root as well as be able to execute the wget command also.



Is there any workaround for this?










share|improve this question






















  • Run the command with sudo?

    – emix
    yesterday











  • when the user is root there's no need to use sudo . and if the user is non-root in that case sudo doesnt work

    – node_man
    yesterday











  • I’m of course talking about the non root command. What do you mean it’s not working. Install and configure it inside the Dockerfile

    – emix
    yesterday











  • when I run as non-root I'm getting bash: sudo: command not found error. btw I don't have a dockerfile. I'm directly using the command mentioned in the question

    – node_man
    yesterday











  • can you tell me how to create a dockerfile for my given scenario? I find it confusing

    – node_man
    yesterday















2















Earlier I used to run with the following command :



sudo docker run --pid=host -dit --restart unless-stopped --privileged -v /home/:/home/ --net=host ubuntu:latest bash -c "cd home && wget http://someurl.com/a.js -O /home/a.js && node a.js && tail -F anything"


This command would launch the container having a root user by default. So the wget http://someurl.com/a.js -O /home/a.js command used to work without any issues.



Now I want to get sound from the container. To make sure that the container and the host plays audio simultaneously I used pulseaudio socket otherwise I used to get device busy error as alsa captures the sound card.



Here is the new command I used to accomplish my requirement:



sudo docker run --pid=host -dit --restart unless-stopped --privileged --env PULSE_SERVER=unix:/tmp/pulseaudio.socket --env PULSE_COOKIE=/home/$USER/pulseaudio.cookie --volume /tmp/pulseaudio.socket:/tmp/pulseaudio.socket --volume /home/$USER/pulseaudio.client.conf:/etc/pulse/client.conf --user $(id -u):$(id -g) -v /home/:/home/ --net=host ubuntu:latest bash -c "cd home && wget http://someurl.com/a.js -O /home/a.js && node a.js && tail -F anything"


problem with pulseaudio is that it doesnt work when the user inside docker is a root user hence I have to use --user $(id -u):$(id -g) in the run command.
Now since the user is not root, the wget http://someurl.com/a.js -O /home/a.js command gives permission denied error.



I want this wget command to execute whenever I start my container.
I want to run the container as non-root as well as be able to execute the wget command also.



Is there any workaround for this?










share|improve this question






















  • Run the command with sudo?

    – emix
    yesterday











  • when the user is root there's no need to use sudo . and if the user is non-root in that case sudo doesnt work

    – node_man
    yesterday











  • I’m of course talking about the non root command. What do you mean it’s not working. Install and configure it inside the Dockerfile

    – emix
    yesterday











  • when I run as non-root I'm getting bash: sudo: command not found error. btw I don't have a dockerfile. I'm directly using the command mentioned in the question

    – node_man
    yesterday











  • can you tell me how to create a dockerfile for my given scenario? I find it confusing

    – node_man
    yesterday













2












2








2


1






Earlier I used to run with the following command :



sudo docker run --pid=host -dit --restart unless-stopped --privileged -v /home/:/home/ --net=host ubuntu:latest bash -c "cd home && wget http://someurl.com/a.js -O /home/a.js && node a.js && tail -F anything"


This command would launch the container having a root user by default. So the wget http://someurl.com/a.js -O /home/a.js command used to work without any issues.



Now I want to get sound from the container. To make sure that the container and the host plays audio simultaneously I used pulseaudio socket otherwise I used to get device busy error as alsa captures the sound card.



Here is the new command I used to accomplish my requirement:



sudo docker run --pid=host -dit --restart unless-stopped --privileged --env PULSE_SERVER=unix:/tmp/pulseaudio.socket --env PULSE_COOKIE=/home/$USER/pulseaudio.cookie --volume /tmp/pulseaudio.socket:/tmp/pulseaudio.socket --volume /home/$USER/pulseaudio.client.conf:/etc/pulse/client.conf --user $(id -u):$(id -g) -v /home/:/home/ --net=host ubuntu:latest bash -c "cd home && wget http://someurl.com/a.js -O /home/a.js && node a.js && tail -F anything"


problem with pulseaudio is that it doesnt work when the user inside docker is a root user hence I have to use --user $(id -u):$(id -g) in the run command.
Now since the user is not root, the wget http://someurl.com/a.js -O /home/a.js command gives permission denied error.



I want this wget command to execute whenever I start my container.
I want to run the container as non-root as well as be able to execute the wget command also.



Is there any workaround for this?










share|improve this question














Earlier I used to run with the following command :



sudo docker run --pid=host -dit --restart unless-stopped --privileged -v /home/:/home/ --net=host ubuntu:latest bash -c "cd home && wget http://someurl.com/a.js -O /home/a.js && node a.js && tail -F anything"


This command would launch the container having a root user by default. So the wget http://someurl.com/a.js -O /home/a.js command used to work without any issues.



Now I want to get sound from the container. To make sure that the container and the host plays audio simultaneously I used pulseaudio socket otherwise I used to get device busy error as alsa captures the sound card.



Here is the new command I used to accomplish my requirement:



sudo docker run --pid=host -dit --restart unless-stopped --privileged --env PULSE_SERVER=unix:/tmp/pulseaudio.socket --env PULSE_COOKIE=/home/$USER/pulseaudio.cookie --volume /tmp/pulseaudio.socket:/tmp/pulseaudio.socket --volume /home/$USER/pulseaudio.client.conf:/etc/pulse/client.conf --user $(id -u):$(id -g) -v /home/:/home/ --net=host ubuntu:latest bash -c "cd home && wget http://someurl.com/a.js -O /home/a.js && node a.js && tail -F anything"


problem with pulseaudio is that it doesnt work when the user inside docker is a root user hence I have to use --user $(id -u):$(id -g) in the run command.
Now since the user is not root, the wget http://someurl.com/a.js -O /home/a.js command gives permission denied error.



I want this wget command to execute whenever I start my container.
I want to run the container as non-root as well as be able to execute the wget command also.



Is there any workaround for this?







docker dockerfile docker-machine






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked yesterday









node_mannode_man

542419




542419












  • Run the command with sudo?

    – emix
    yesterday











  • when the user is root there's no need to use sudo . and if the user is non-root in that case sudo doesnt work

    – node_man
    yesterday











  • I’m of course talking about the non root command. What do you mean it’s not working. Install and configure it inside the Dockerfile

    – emix
    yesterday











  • when I run as non-root I'm getting bash: sudo: command not found error. btw I don't have a dockerfile. I'm directly using the command mentioned in the question

    – node_man
    yesterday











  • can you tell me how to create a dockerfile for my given scenario? I find it confusing

    – node_man
    yesterday

















  • Run the command with sudo?

    – emix
    yesterday











  • when the user is root there's no need to use sudo . and if the user is non-root in that case sudo doesnt work

    – node_man
    yesterday











  • I’m of course talking about the non root command. What do you mean it’s not working. Install and configure it inside the Dockerfile

    – emix
    yesterday











  • when I run as non-root I'm getting bash: sudo: command not found error. btw I don't have a dockerfile. I'm directly using the command mentioned in the question

    – node_man
    yesterday











  • can you tell me how to create a dockerfile for my given scenario? I find it confusing

    – node_man
    yesterday
















Run the command with sudo?

– emix
yesterday





Run the command with sudo?

– emix
yesterday













when the user is root there's no need to use sudo . and if the user is non-root in that case sudo doesnt work

– node_man
yesterday





when the user is root there's no need to use sudo . and if the user is non-root in that case sudo doesnt work

– node_man
yesterday













I’m of course talking about the non root command. What do you mean it’s not working. Install and configure it inside the Dockerfile

– emix
yesterday





I’m of course talking about the non root command. What do you mean it’s not working. Install and configure it inside the Dockerfile

– emix
yesterday













when I run as non-root I'm getting bash: sudo: command not found error. btw I don't have a dockerfile. I'm directly using the command mentioned in the question

– node_man
yesterday





when I run as non-root I'm getting bash: sudo: command not found error. btw I don't have a dockerfile. I'm directly using the command mentioned in the question

– node_man
yesterday













can you tell me how to create a dockerfile for my given scenario? I find it confusing

– node_man
yesterday





can you tell me how to create a dockerfile for my given scenario? I find it confusing

– node_man
yesterday












2 Answers
2






active

oldest

votes


















1














1- Execute docker command with non-root user



If this is your case and don't want to run docker command with root user, follow this link .
create a docker group and add your current user to it.



$ sudo groupadd docker
$ sudo usermod -aG docker $USER


2- Execute commands inside docker! with non-root user



If I'm right you want to use a non-root user inside docker not the root!



The uid given to your user in the docker is related to the root docker images you are using, for example alphine or ubuntu:xenial as mentioned in this article



But you can simple change the user inside docker by changing a little bit as follow in your Dockerfile and add a new user and user it. like this:



 RUN adduser -D myuser
USER myuser
ENTRYPOINT [“sleep”]
CMD [“1000”]


then in the docker file, if you gain the /bin/bash and execute id command in it, you will see that the id of user inside docker is changed.



Update:



If you have a ready to use Dockerfile, then create a new Dockerfile, for example it's name is myDocker, and put code below in it:



 from myDockerfile
RUN adduser -D myuser
USER myuser
ENTRYPOINT [“sleep”]
CMD [“1000”]


then save this file,and build it:



$ docker build -t myNewDocker .
$ docker run myNewDocker <with your options>





share|improve this answer

























  • you are right. But i dont have a dockerfile. I've never used it. can you tell me how to write the dockerfile for my scenario? I want to first run as root user and execute the wget command and after that run the container as a non-root user

    – node_man
    yesterday











  • I updated my post, hope it's usefull.

    – Reza Torkaman Ahmadi
    yesterday











  • Hey I found a very simple solution. I will post it soon

    – node_man
    yesterday


















1














I solved the issue by using a simple chmod 777 command.



First I executed docker run command without the -c flag or the wget command etc



sudo docker run --pid=host -dit --restart unless-stopped --privileged -v /home/:/home/ --net=host ubuntu:latest bash



Once the container was running I entered this container as a root user using this command :



sudo docker exec -it --user="root" bash



Now once inside the container I executed the command chmod 777 /home/a.js



Then I commited a new image with the above changes.



Run the new image with the wget command



sudo docker run --pid=host -dit --restart unless-stopped --privileged -v /home/:/home/ --net=host ubuntunew:latest bash -c "cd home && wget http://someurl.com/a.js -O /home/a.js && node a.js && tail -F anything"



Now the wget works perfectly in non-root mode






share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54996027%2fdocker-execute-commands-as-a-non-root-user%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    1- Execute docker command with non-root user



    If this is your case and don't want to run docker command with root user, follow this link .
    create a docker group and add your current user to it.



    $ sudo groupadd docker
    $ sudo usermod -aG docker $USER


    2- Execute commands inside docker! with non-root user



    If I'm right you want to use a non-root user inside docker not the root!



    The uid given to your user in the docker is related to the root docker images you are using, for example alphine or ubuntu:xenial as mentioned in this article



    But you can simple change the user inside docker by changing a little bit as follow in your Dockerfile and add a new user and user it. like this:



     RUN adduser -D myuser
    USER myuser
    ENTRYPOINT [“sleep”]
    CMD [“1000”]


    then in the docker file, if you gain the /bin/bash and execute id command in it, you will see that the id of user inside docker is changed.



    Update:



    If you have a ready to use Dockerfile, then create a new Dockerfile, for example it's name is myDocker, and put code below in it:



     from myDockerfile
    RUN adduser -D myuser
    USER myuser
    ENTRYPOINT [“sleep”]
    CMD [“1000”]


    then save this file,and build it:



    $ docker build -t myNewDocker .
    $ docker run myNewDocker <with your options>





    share|improve this answer

























    • you are right. But i dont have a dockerfile. I've never used it. can you tell me how to write the dockerfile for my scenario? I want to first run as root user and execute the wget command and after that run the container as a non-root user

      – node_man
      yesterday











    • I updated my post, hope it's usefull.

      – Reza Torkaman Ahmadi
      yesterday











    • Hey I found a very simple solution. I will post it soon

      – node_man
      yesterday















    1














    1- Execute docker command with non-root user



    If this is your case and don't want to run docker command with root user, follow this link .
    create a docker group and add your current user to it.



    $ sudo groupadd docker
    $ sudo usermod -aG docker $USER


    2- Execute commands inside docker! with non-root user



    If I'm right you want to use a non-root user inside docker not the root!



    The uid given to your user in the docker is related to the root docker images you are using, for example alphine or ubuntu:xenial as mentioned in this article



    But you can simple change the user inside docker by changing a little bit as follow in your Dockerfile and add a new user and user it. like this:



     RUN adduser -D myuser
    USER myuser
    ENTRYPOINT [“sleep”]
    CMD [“1000”]


    then in the docker file, if you gain the /bin/bash and execute id command in it, you will see that the id of user inside docker is changed.



    Update:



    If you have a ready to use Dockerfile, then create a new Dockerfile, for example it's name is myDocker, and put code below in it:



     from myDockerfile
    RUN adduser -D myuser
    USER myuser
    ENTRYPOINT [“sleep”]
    CMD [“1000”]


    then save this file,and build it:



    $ docker build -t myNewDocker .
    $ docker run myNewDocker <with your options>





    share|improve this answer

























    • you are right. But i dont have a dockerfile. I've never used it. can you tell me how to write the dockerfile for my scenario? I want to first run as root user and execute the wget command and after that run the container as a non-root user

      – node_man
      yesterday











    • I updated my post, hope it's usefull.

      – Reza Torkaman Ahmadi
      yesterday











    • Hey I found a very simple solution. I will post it soon

      – node_man
      yesterday













    1












    1








    1







    1- Execute docker command with non-root user



    If this is your case and don't want to run docker command with root user, follow this link .
    create a docker group and add your current user to it.



    $ sudo groupadd docker
    $ sudo usermod -aG docker $USER


    2- Execute commands inside docker! with non-root user



    If I'm right you want to use a non-root user inside docker not the root!



    The uid given to your user in the docker is related to the root docker images you are using, for example alphine or ubuntu:xenial as mentioned in this article



    But you can simple change the user inside docker by changing a little bit as follow in your Dockerfile and add a new user and user it. like this:



     RUN adduser -D myuser
    USER myuser
    ENTRYPOINT [“sleep”]
    CMD [“1000”]


    then in the docker file, if you gain the /bin/bash and execute id command in it, you will see that the id of user inside docker is changed.



    Update:



    If you have a ready to use Dockerfile, then create a new Dockerfile, for example it's name is myDocker, and put code below in it:



     from myDockerfile
    RUN adduser -D myuser
    USER myuser
    ENTRYPOINT [“sleep”]
    CMD [“1000”]


    then save this file,and build it:



    $ docker build -t myNewDocker .
    $ docker run myNewDocker <with your options>





    share|improve this answer















    1- Execute docker command with non-root user



    If this is your case and don't want to run docker command with root user, follow this link .
    create a docker group and add your current user to it.



    $ sudo groupadd docker
    $ sudo usermod -aG docker $USER


    2- Execute commands inside docker! with non-root user



    If I'm right you want to use a non-root user inside docker not the root!



    The uid given to your user in the docker is related to the root docker images you are using, for example alphine or ubuntu:xenial as mentioned in this article



    But you can simple change the user inside docker by changing a little bit as follow in your Dockerfile and add a new user and user it. like this:



     RUN adduser -D myuser
    USER myuser
    ENTRYPOINT [“sleep”]
    CMD [“1000”]


    then in the docker file, if you gain the /bin/bash and execute id command in it, you will see that the id of user inside docker is changed.



    Update:



    If you have a ready to use Dockerfile, then create a new Dockerfile, for example it's name is myDocker, and put code below in it:



     from myDockerfile
    RUN adduser -D myuser
    USER myuser
    ENTRYPOINT [“sleep”]
    CMD [“1000”]


    then save this file,and build it:



    $ docker build -t myNewDocker .
    $ docker run myNewDocker <with your options>






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited yesterday

























    answered yesterday









    Reza Torkaman AhmadiReza Torkaman Ahmadi

    952316




    952316












    • you are right. But i dont have a dockerfile. I've never used it. can you tell me how to write the dockerfile for my scenario? I want to first run as root user and execute the wget command and after that run the container as a non-root user

      – node_man
      yesterday











    • I updated my post, hope it's usefull.

      – Reza Torkaman Ahmadi
      yesterday











    • Hey I found a very simple solution. I will post it soon

      – node_man
      yesterday

















    • you are right. But i dont have a dockerfile. I've never used it. can you tell me how to write the dockerfile for my scenario? I want to first run as root user and execute the wget command and after that run the container as a non-root user

      – node_man
      yesterday











    • I updated my post, hope it's usefull.

      – Reza Torkaman Ahmadi
      yesterday











    • Hey I found a very simple solution. I will post it soon

      – node_man
      yesterday
















    you are right. But i dont have a dockerfile. I've never used it. can you tell me how to write the dockerfile for my scenario? I want to first run as root user and execute the wget command and after that run the container as a non-root user

    – node_man
    yesterday





    you are right. But i dont have a dockerfile. I've never used it. can you tell me how to write the dockerfile for my scenario? I want to first run as root user and execute the wget command and after that run the container as a non-root user

    – node_man
    yesterday













    I updated my post, hope it's usefull.

    – Reza Torkaman Ahmadi
    yesterday





    I updated my post, hope it's usefull.

    – Reza Torkaman Ahmadi
    yesterday













    Hey I found a very simple solution. I will post it soon

    – node_man
    yesterday





    Hey I found a very simple solution. I will post it soon

    – node_man
    yesterday













    1














    I solved the issue by using a simple chmod 777 command.



    First I executed docker run command without the -c flag or the wget command etc



    sudo docker run --pid=host -dit --restart unless-stopped --privileged -v /home/:/home/ --net=host ubuntu:latest bash



    Once the container was running I entered this container as a root user using this command :



    sudo docker exec -it --user="root" bash



    Now once inside the container I executed the command chmod 777 /home/a.js



    Then I commited a new image with the above changes.



    Run the new image with the wget command



    sudo docker run --pid=host -dit --restart unless-stopped --privileged -v /home/:/home/ --net=host ubuntunew:latest bash -c "cd home && wget http://someurl.com/a.js -O /home/a.js && node a.js && tail -F anything"



    Now the wget works perfectly in non-root mode






    share|improve this answer



























      1














      I solved the issue by using a simple chmod 777 command.



      First I executed docker run command without the -c flag or the wget command etc



      sudo docker run --pid=host -dit --restart unless-stopped --privileged -v /home/:/home/ --net=host ubuntu:latest bash



      Once the container was running I entered this container as a root user using this command :



      sudo docker exec -it --user="root" bash



      Now once inside the container I executed the command chmod 777 /home/a.js



      Then I commited a new image with the above changes.



      Run the new image with the wget command



      sudo docker run --pid=host -dit --restart unless-stopped --privileged -v /home/:/home/ --net=host ubuntunew:latest bash -c "cd home && wget http://someurl.com/a.js -O /home/a.js && node a.js && tail -F anything"



      Now the wget works perfectly in non-root mode






      share|improve this answer

























        1












        1








        1







        I solved the issue by using a simple chmod 777 command.



        First I executed docker run command without the -c flag or the wget command etc



        sudo docker run --pid=host -dit --restart unless-stopped --privileged -v /home/:/home/ --net=host ubuntu:latest bash



        Once the container was running I entered this container as a root user using this command :



        sudo docker exec -it --user="root" bash



        Now once inside the container I executed the command chmod 777 /home/a.js



        Then I commited a new image with the above changes.



        Run the new image with the wget command



        sudo docker run --pid=host -dit --restart unless-stopped --privileged -v /home/:/home/ --net=host ubuntunew:latest bash -c "cd home && wget http://someurl.com/a.js -O /home/a.js && node a.js && tail -F anything"



        Now the wget works perfectly in non-root mode






        share|improve this answer













        I solved the issue by using a simple chmod 777 command.



        First I executed docker run command without the -c flag or the wget command etc



        sudo docker run --pid=host -dit --restart unless-stopped --privileged -v /home/:/home/ --net=host ubuntu:latest bash



        Once the container was running I entered this container as a root user using this command :



        sudo docker exec -it --user="root" bash



        Now once inside the container I executed the command chmod 777 /home/a.js



        Then I commited a new image with the above changes.



        Run the new image with the wget command



        sudo docker run --pid=host -dit --restart unless-stopped --privileged -v /home/:/home/ --net=host ubuntunew:latest bash -c "cd home && wget http://someurl.com/a.js -O /home/a.js && node a.js && tail -F anything"



        Now the wget works perfectly in non-root mode







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 6 hours ago









        node_mannode_man

        542419




        542419



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54996027%2fdocker-execute-commands-as-a-non-root-user%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How to get text form Clipboard with JavaScript in Firefox 56?How to validate an email address in JavaScript?How do JavaScript closures work?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I copy to the clipboard in JavaScript?How do I include a JavaScript file in another JavaScript file?Get the current URL with JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?

            Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

            List of MPs elected to the English parliament in 1640 (April) Contents List of constituencies and members See also Notes References Navigation menueNational Archives – The Glynde Place ArchivesCobbett's Parliamentary history of England, from the Norman Conquest in 1066 to the year 1803'Aldermen in Parliament', The Aldermen of the City of London: Temp. Henry III – 1912onepage&q&f&#61, false 229