Dockerfile 和entrypoint:

Dockerfile是容器启动前执行的命令,entrypoint是容器系统启动后执行的命令

entrypint.sh示例:

#!/bin/sh

set -e

groupadd docker -g "$GROUP_ID" useradd docker --shell /bin/bash -u "$USER_ID" -g "$GROUP_ID"

export HOME=/home/docker

exec gosu "$USER_ID:$GROUP_ID" "$@"

:wq

注: 该脚本内容是为容器创建1各本地账号,uid和gid均为变量,方便用户创建容器时调整(以和宿主机账号一致)

Dockerfile要新加(名字必须为Dockerfile)

apt-get install gosu

COPY entrypoint.sh /usr/local/bin/entrypoint.sh ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] RUN chmod +x /usr/local/bin/entrypoint.sh

Dockerfile和entrypoint.sh放到同1目录下,生成image命令:docker built -t image:1.0 ./