how to use apt/sudo in alpine-based docker image
another method of obtaining basic tools like sudo and curl?
I believe alpine uses apk
instead of apt
Try something like this to install basic tools like curl
and sudo
RUN apk add curl sudo
How to use sudo inside a docker container?
Just got it. As regan pointed out, I had to add the user to the sudoers group. But the main reason was I'd forgotten to update the repositories cache, so apt-get couldn't find the sudo package. It's working now. Here's the completed code:
FROM ubuntu:12.04
RUN apt-get update && \
apt-get -y install sudo
RUN useradd -m docker && echo "docker:docker" | chpasswd && adduser docker sudo
USER docker
CMD /bin/bash
correct method to create user in alpine docker container so that sudo works correctly
From man sudo
:
-s, --shell
Run the shell specified by the SHELL environment variable if it is set or the shell specified by the invoking user's password database entry.
You have neither SHELL
variable set, nor correct (interactive) default shell set in /etc/passwd
for user payara
. This is because you are creating a system user (-S
) - this user has a default shell /bin/false
(which just exits with exit code 1
- you may check with echo $?
after unsuccessfull sudo -s
).
You may overcome this in different ways:
a) specify the SHELL
variable:
bash-4.4$ SHELL=/bin/bash sudo -s
bed662af470d:~#
b) use su
, which will use the default root
's shell:
bash-4.4$ sudo su -
bed662af470d:~#
c) just run the required privileged commands with sudo
directly, without spawning an interactive shell.
How to run bash as user root on alpine images with docker? su: must be suid to work properly
You can run a command within the container as root using --user root
. To get a shell:
docker exec -it --user root kong sh
Related Topics
How to Read a Sector Using a Bio Request in Linux Kernel
How to Echo a Sum of a Variable and a Number
How to Get in Script Whether Valgrind Found Memory Leaks
Detect Underlying Platform/Flavour in Cmake
Linux C/C++ Socket Send in Multi-Thread Code
Alsa Cannot Set Sample Format[Ffmpeg]
How to Make Ffmpeg Write Its Output to a Named Pipe
How to Start Node.Js on Port 80 on a Linux Server
Linux: Create Random Directory/File Hierarchy
Lowest Latency Notification Method Between Process Under Linux
How to Use Awk for a Compressed File
Will Ctrl+C Send Sigint Signals to Both Parent and Child Processes in Linux
How to Keep Executable Code in Memory Even Under Memory Pressure? in Linux
How to Catch the L3-Cache Hits and Misses by Perf Tool in Linux