Reputation: 115
I am trying to test how to add user
my docker info is:
% docker info
Client:
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc., v0.7.1)
compose: Docker Compose (Docker Inc., v2.2.1)
scan: Docker Scan (Docker Inc., 0.9.0)
Server:
Containers: 94
Running: 0
Paused: 0
Stopped: 94
Images: 11
Server Version: 20.10.11
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 2
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 7b11cfaabd73bb80907dd23182b9347b4245eb5d
runc version: v1.0.2-0-g52b36a2
init version: de40ad0
Security Options:
seccomp
Profile: default
cgroupns
Kernel Version: 5.10.76-linuxkit
Operating System: Docker Desktop
OSType: linux
Architecture: aarch64
CPUs: 4
Total Memory: 1.942GiB
Name: docker-desktop
ID: BNVF:OFMF:5YJE:SAGF:CVBA:IOGG:36BQ:G63I:J6YM:KWFY:P5CL:EX3U
Docker Root Dir: /var/lib/docker
Debug Mode: true
File Descriptors: 48
Goroutines: 46
System Time: 2022-01-16T15:49:03.553220221Z
EventsListeners: 3
HTTP Proxy: http.docker.internal:3128
HTTPS Proxy: http.docker.internal:3128
Registry: https://index.docker.io/v1/
Labels:
Experimental: true
Insecure Registries:
127.0.0.0/8
Registry Mirrors:
http://hub-mirror.c.163.com/
Live Restore Enabled: false
my docker file is like:
FROM ubuntu:latest
MAINTAINER xueshan
RUN groupadd -r redis && useradd -r -g redis redis
USER redis
CMD ["redis-server"]
% docker build TEST -t testuser
[+] Building 0.1s (6/6) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 163B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/ubuntu:latest 0.0s
=> [1/2] FROM docker.io/library/ubuntu:latest 0.0s
=> CACHED [2/2] RUN groupadd -r redis && useradd -r -g redis redis 0.0s
=> exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:74f15b450612cc59e37228be496e7c91f2f69b876073ec1803914932bd777eb2 0.0s
=> => naming to docker.io/library/testuser 0.0s
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
% docker run -it testuser
docker: Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "redis-server": executable file not found in $PATH: unknown.
ERRO[0000] error waiting for container: context canceled
from the output of buliding image, it seems that no error happened ...[?]
I am wondering how to solve this problem and run docker with user redis
or I have to add the path of this docker file as $path?
and I tried with docker ps
% docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
the result seems to show that no active container ... [?]
what I expect to see is that after successfully building the image, if I run it with docker run -it 'image'
, the user at the terminal should change to redis
.
2021/1/20 3rd Update
2021/1/20 4th Update. this is what I expect to see
https://dockerlabs.collabnix.com/beginners/dockerfile/user.html https://programming.vip/docs/detailed-explanation-of-docker-dockerfile-instructions-and-practical-cases.html
Upvotes: 1
Views: 10155
Reputation: 700
Your problem isn't with adding the user. The problem is:
starting container process caused: exec: "redis-server": executable file not found in $PATH: unknown.
Meaning redis-server
isn't in your $PATH
According to your Dockerfile
you didn't install redis
.
Try this Dockerfile
:
FROM ubuntu:latest
MAINTAINER xueshan
RUN apt update && \
apt install -y –no-install-recommends redis && \
rm -rf /var/lib/apt/lists/*
RUN groupadd -r redis && useradd -r -g redis redis
USER redis
CMD ["redis-server"]
Upvotes: 4