docker_practice/image/dockerfile/user.md

27 lines
1.2 KiB
Go
Raw Normal View History

### USER
`USER <用户名>[:<用户组>]`
`USER` `WORKDIR` `WORKDIR` `USER` `RUN`, `CMD` `ENTRYPOINT`
`WORKDIR` `USER`
```docker
RUN groupadd -r redis && useradd -r -g redis redis
USER redis
RUN [ "redis-server" ]
```
`root` 使 `su` `sudo` TTY 使 [`gosu`](https://github.com/tianon/gosu)。
```docker
# redis 使 gosu
RUN groupadd -r redis && useradd -r -g redis redis
# gosu
RUN wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/1.7/gosu-amd64" \
&& chmod +x /usr/local/bin/gosu \
&& gosu nobody true
# CMD
CMD [ "exec", "gosu", "redis", "redis-server" ]
```