You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 15, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Jan 15, 2023. It is now read-only.
First of all, thanks for creating and maintaining such a wonderful docker image! You're always so quick to update when a new version of node comes out 💯. And now for my question...
In the official docker-node repo, there is a Best Practices doc that explains you should create a user instead of running as root.
# Add our user and group first to make sure their IDs get assigned consistentlyRUN groupadd -r app && useradd -r -g app app
Does alpine-node have a similar best practice?
What is the equivalent groupadd and useradd in Alpine?
Reacted by miguel, Jun Makii, Alexander A. Prokhorov, Wojtek Erbetowski, Hadrien TOMA, pepperpin, Oliver Weiler, José Cage , madhav1984mishra, Chris Duncan and 10 more
I think I figured it out. The -S flag will add to system group which is equivalent to -r in Ubuntu.
RUN addgroup -S app && adduser -S -G app app
Reacted by François Nguyen, Rafael Roman Otero, Eric Simmerman, Sebastian Radloff, Mohsen, Abhinav, Eron Alves, Victor Gazotti, Zarne Dravitzki, Bryce Bedwell and 94 more
Reacted by Tim Nolet, Glen K. Peterson, Alex Ellis, Arman Shahinyan, Michael Davis, Ninh Pham, Randy Lam, Ashley Blackmore, Jacob Wang, Bill Himmelsbach and 16 more
Reacted by Anderson Scouto da Silva (Dan), Pushpak Chhajed and Francisco Barros
Reacted by Deeptiman Pattnaik, Pushpak Chhajed and Adam Flaxman
Should I add a best practices to this repo? Or are we close to getting alpine in the official docker node and just wait to add it there? See docker-node/pull/156.
Hey @styfle just wanted to stop by and say thank you for sharing this! I'm thinking about curating a list of best practices for docker / alpine because I'm personally having a hard time making the right decisions.
Reacted by Steven, kiamars, Márcio de Sousa, jingo, José Cage , Pedro Galvão, Dmitri and Casey Burnett
@ORESoftware yeah it is – what version you running?
$ docker run alpine:3.6 adduserBusyBox v1.26.2 (2017-06-11 06:38:32 GMT) multi-call binary.Usage: adduser [OPTIONS] USER [GROUP]Create new user, or add USER to GROUP -h DIR Home directory -g GECOS GECOS field -s SHELL Login shell -G GRP Add user to existing group -S Create a system user -D Don't assign a password -H Don't create home directory -u UID User id -k SKEL Skeleton directory (/etc/skel)
$ docker run alpine:3.4 adduserBusyBox v1.24.2 (2017-01-18 14:13:46 GMT) multi-call binary.Usage: adduser [OPTIONS] USER [GROUP]Create new user, or add USER to GROUP -h DIR Home directory -g GECOS GECOS field -s SHELL Login shell -G GRP Add user to existing group -S Create a system user -D Don't assign a password -H Don't create home directory -u UID User id -k SKEL Skeleton directory (/etc/skel)
Reacted by Alexander Mills, Victor Login, Simon Dowling, Eva Pace, Milan Karunarathne, Glen K. Peterson, hvle, Arman Shahinyan, Caio Mathielo, Mark Kremer and 13 more
For some reason using the command @styfle posted, my user stayed at the nogroup.
I tested a lot and this worked:
RUN addgroup -S myawesomegroup
RUN adduser -S myawesomeuser -G myawesomegroup
:)
Reacted by Steven, Yan Lytovka, Mardari Grigore, Austin Delamar, Imesh Gunaratne, Andrei Vedovato, Christian Nicolai, José Cage , Jaakko Korhonen, Pascal Andy and 3 more
Setting the UID to 1000 ensures we will not run in permissions issues when mapping volumes from our computer to the running container, once 1000 is the first UID assigned to a non root user in Linux, at least in Debian and Ubuntu ;)
Reacted by Nick Tobolski, Glen K. Peterson, Charles Santos, Blake Watkins, Bastien Teinturier, Josta Yee, Simon Vadée, S. Rey-Coyrehourcq, Drew Morris, Loki and 31 more
Setting the UID to 1000 ensures we will not run in permissions issues when mapping volumes from our computer to the running container, once 1000 is the first UID assigned to a non root user in Linux, at least in Debian and Ubuntu ;)
docker-compose up
Building orchestrator
Step 1/13 : FROM node:10-alpine
---> 7ca2f9cb5536
Step 2/13 : ENV user orchestrator
---> Using cache
---> bb0d334f29c6
Step 3/13 : ENV workdir /usr/src/app/
---> Using cache
---> a14d0251cf82
Step 4/13 : RUN addgroup -g 1000 -S $user && adduser -u 1000 -S -G $user $user
---> Running in 8545a3ed4d32
addgroup: gid '1000' in use
ERROR: Service 'orchestrator' failed to build: The command '/bin/sh -c addgroup -g 1000 -S $user && adduser -u 1000 -S -G $user $user' returned a non-zero code: 1
Finally I run yarn dc-build to build a docker image.
Reacted by Paulo Renato, Nick Sweeting, Alan Costa, Steen Manniche, Kim Carter, Jürgen Hörmann, Chauncey Garrett, Adrien Lemaire, Maurizio Brioschi, José Cage and 15 more
Reacted by Igor Pellegrini, Robin and Vitor L Cavalcanti
Why is mobydick added to the sudoers?
Why is mobydick able to run ALL commands as root? In your example there don't appear to be any commands following the sudoers insertion that require root perms.
Adding mobydick to the sudoers list is generally not needed for images that are distributed to end consumers (i.e. they just run container from image and that's it). However, if you are a developer doing lots of development stuff on your local machine, you will find it convenient that mobydick is one of sudoers, when it comes to installing extra packages you might need for development, e.g., installing certain npm packages/ruby gems might require additional software packages installed.
You can do this inside Dockerfile and rebuild the image, but that takes longer than doing it on the fly inside the current running container. (I am not saying doing it inside container is enough - you will still need to update Dockerfile accordingly about adding new packages.)
In the Dockerfile I demonstrated above, all commands are run in the capacity of root user until it meets the line USER mobydick. All commands that come after this line will be assumed to run as mobydick.
Activity
mhart commentedon Jul 7, 2016
Try
adduserandaddgroup– lemme know if that worksstyfle commentedon Jul 7, 2016
I think I figured it out. The
-Sflag will add to system group which is equivalent to-rin Ubuntu.RUN addgroup -S app && adduser -S -G app appstyfle commentedon Jul 7, 2016
Should I add a best practices to this repo? Or are we close to getting alpine in the official docker node and just wait to add it there? See docker-node/pull/156.
mhart commentedon Jul 7, 2016
Yeah, let's wait for the official image – I'm sure they'll be getting that in soon
Thanks for highlighting this though and finding the appropriate command line options!
peterpme commentedon Dec 28, 2016
Hey @styfle just wanted to stop by and say thank you for sharing this! I'm thinking about curating a list of best practices for docker / alpine because I'm personally having a hard time making the right decisions.
styfle commentedon Jan 6, 2017
@peterpme I am working with the official docker-node image to get these practices updated.
See linked PR 99 above.
ORESoftware commentedon Sep 9, 2017
adduser isn't available on Alpine out of the box?
mhart commentedon Sep 9, 2017
@ORESoftware yeah it is – what version you running?
evaporei commentedon Feb 1, 2018
For some reason using the command @styfle posted, my user stayed at the
nogroup.I tested a lot and this worked:
:)
Exadra37 commentedon Mar 3, 2018
For latest Alpine image, the
3.7the correct command is:RUN addgroup -g 1000 -S username && \ adduser -u 1000 -S username -G usernameSetting the UID to
1000ensures we will not run in permissions issues when mapping volumes from our computer to the running container, once1000is the first UID assigned to a non root user in Linux, at least in Debian and Ubuntu ;)Testing on Alpine 3.7
binarymist commentedon Oct 18, 2018
@Exadra37
elquimista commentedon Oct 18, 2018
Here's what I do using docker-compose:
Dockerfiledocker-compose.yml.envpackage.json{ "scripts": { "dc": "GID=$(id -g) UID=$(id -u) docker-compose", "dc-build": "yarn dc build" } }Finally I run
yarn dc-buildto build a docker image.Exadra37 commentedon Oct 18, 2018
@binarymist
As the error points out the group id
1000is already in use.This happens because the node image already as the user
nodewith id1000and group id1000.So no need for you to add your user when extending a node image, unless id is not
1000.The @elquimista solution works with any user and group id and you can use it without docker compose, like:
binarymist commentedon Oct 19, 2018
@Exadra37
Yeah, that's my point.
@elquimista
Your solution is looking good (terse, readable, not too clever). The best I could find until this was the suggested (https://denibertovic.com/posts/handling-permissions-with-docker-volumes/) which has a few problems of it's own (ncopa/su-exec#2 (comment))
Nice!
Just a couple of questions:
Why is mobydick added to the sudoers?
Why is mobydick able to run
ALLcommands asroot? In your example there don't appear to be any commands following the sudoers insertion that requirerootperms.elquimista commentedon Oct 19, 2018
@binarymist
Adding mobydick to the sudoers list is generally not needed for images that are distributed to end consumers (i.e. they just run container from image and that's it). However, if you are a developer doing lots of development stuff on your local machine, you will find it convenient that mobydick is one of sudoers, when it comes to installing extra packages you might need for development, e.g., installing certain npm packages/ruby gems might require additional software packages installed.
You can do this inside Dockerfile and rebuild the image, but that takes longer than doing it on the fly inside the current running container. (I am not saying doing it inside container is enough - you will still need to update Dockerfile accordingly about adding new packages.)
In the Dockerfile I demonstrated above, all commands are run in the capacity of root user until it meets the line
USER mobydick. All commands that come after this line will be assumed to run as mobydick.binarymist commentedon Oct 19, 2018
Yip, understand that, good work!