【发布时间】:2017-06-16 14:58:10
【问题描述】:
作为我的 Docker 映像的一部分,我有以下 ENTRYPOINT 脚本:
#!/bin/bash
set -e
if [ -z "${UID}" ]; then
uid=1000;
else
uid=${UID};
fi
if [ -z "${GID}" ]; then
gid=1000;
else
gid=${GID};
fi
echo "UID: $uid"
echo "GID: $gid"
data_dir="/var/www/html"
usermod -u "$uid" www-data && groupmod -g "$gid" www-data
chown -R www-data:root "$data_dir"
if [ -d "$data_dir" ]; then
chgrp -RH www-data "$data_dir"
chmod -R g+w "$data_dir"
find "$data_dir" -type d -exec chmod 2775 {} +
find "$data_dir" -type f -exec chmod ug+rw {} +
fi
composer_cache_dir="/var/www/.composer"
mkdir -p "$composer_cache_dir"
chown -R www-data:root "$composer_cache_dir"
if [ -d "$composer_cache_dir" ]; then
chgrp -R www-data "$composer_cache_dir"
chmod -R g+w "$composer_cache_dir"
fi
a2enmod rewrite expires
rm -f /var/run/apache2/apache2.pid
source /etc/apache2/envvars && exec /usr/sbin/apache2 -DFOREGROUND "$@"
镜像编译成功。当我尝试通过运行以下命令docker run -it temp bash 来运行容器时,我得到了以下输出:
UID: 0
GID: 1000
usermod: UID '0' already exists
Enabling module rewrite.
Enabling module expires.
To activate the new configuration, you need to run:
service apache2 restart
AH00112: Warning: DocumentRoot [/var/www/html/public_html] does not exist
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
为什么我的UID 是0?我在这里找不到我的错误,任何帮助都非常受欢迎。
更新:
在脚本上更改这一行:
if [ "$UID" != 0 ]; then
uid=1000;
else
uid=${UID};
fi
仍然将0 分配给uid,是因为var 名称吗? (我已经使用docker build --no-cache -t temp . 重建了图像,所以没有使用缓存)
【问题讨论】: