如何修复 ln -s 在 Docker 中不起作用?
How do I fix ln -s not working in Docker?
Step 3/10 : RUN mkdir -p /etc/nginx/{sites-available,sites-enabled}
Step 4/10 : COPY nginx.conf /etc/nginx/
Step 5/10 : COPY sites-available/*.conf /etc/nginx/sites-available/
Step 6/10 : RUN ln -s /etc/nginx/sites-available/* /etc/nginx/sites-enabled/
---> Running in a2f39a3fd6b3
ln: /etc/nginx/sites-enabled/: No such file or directory
ln: /etc/nginx/sites-enabled/: No such file or directory
ln: /etc/nginx/sites-enabled/: No such file or directory
ln: /etc/nginx/sites-enabled/: No such file or directory
ln: /etc/nginx/sites-enabled/: No such file or directory
ln: /etc/nginx/sites-enabled/: No such file or directory
ln: /etc/nginx/sites-enabled/: No such file or directory
ln: /etc/nginx/sites-enabled/: No such file or directory
The command '/bin/sh -c ln -s /etc/nginx/sites-available/* /etc/nginx/sites-enabled/*' returned a non-zero code: 1
知道为什么这不起作用吗? ^^
我在 docker 容器外尝试了所有这些命令,它似乎有效
这可以通过使用以下语句将文件直接复制到 sites-enabled
目录来解决:
COPY sites-available/*.conf /etc/nginx/sites-enabled/
您的第 3 步包含一个 bashism:
mkdir -p /etc/nginx/{sites-available,sites-enabled}
使用默认 /bin/sh,这将创建一个目录而不是您想要的两个目录:
$ docker run -it --rm nginx /bin/sh
# ls -al /etc/nginx
total 48
drwxr-xr-x 3 root root 4096 Dec 28 15:20 .
drwxr-xr-x 1 root root 4096 Jan 26 19:46 ..
drwxr-xr-x 2 root root 4096 Dec 28 15:20 conf.d
-rw-r--r-- 1 root root 1007 Nov 19 12:50 fastcgi_params
-rw-r--r-- 1 root root 2837 Nov 19 12:50 koi-utf
-rw-r--r-- 1 root root 2223 Nov 19 12:50 koi-win
-rw-r--r-- 1 root root 5231 Nov 19 12:50 mime.types
lrwxrwxrwx 1 root root 22 Nov 19 12:50 modules -> /usr/lib/nginx/modules
-rw-r--r-- 1 root root 643 Nov 19 12:50 nginx.conf
-rw-r--r-- 1 root root 636 Nov 19 12:50 scgi_params
-rw-r--r-- 1 root root 664 Nov 19 12:50 uwsgi_params
-rw-r--r-- 1 root root 3610 Nov 19 12:50 win-utf
# mkdir -p /etc/nginx/{sites-available,sites-enabled}
# ls -al /etc/nginx
total 56
drwxr-xr-x 1 root root 4096 Jan 26 19:47 .
drwxr-xr-x 1 root root 4096 Jan 26 19:46 ..
drwxr-xr-x 2 root root 4096 Dec 28 15:20 conf.d
-rw-r--r-- 1 root root 1007 Nov 19 12:50 fastcgi_params
-rw-r--r-- 1 root root 2837 Nov 19 12:50 koi-utf
-rw-r--r-- 1 root root 2223 Nov 19 12:50 koi-win
-rw-r--r-- 1 root root 5231 Nov 19 12:50 mime.types
lrwxrwxrwx 1 root root 22 Nov 19 12:50 modules -> /usr/lib/nginx/modules
-rw-r--r-- 1 root root 643 Nov 19 12:50 nginx.conf
-rw-r--r-- 1 root root 636 Nov 19 12:50 scgi_params
-rw-r--r-- 1 root root 664 Nov 19 12:50 uwsgi_params
-rw-r--r-- 1 root root 3610 Nov 19 12:50 win-utf
drwxr-xr-x 2 root root 4096 Jan 26 19:47 {sites-available,sites-enabled}
对于/bin/sh,您需要单独列出它们:
# mkdir -p /etc/nginx/sites-available /etc/nginx/sites-enabled
# ls -al /etc/nginx
total 64
drwxr-xr-x 1 root root 4096 Jan 26 19:49 .
drwxr-xr-x 1 root root 4096 Jan 26 19:46 ..
drwxr-xr-x 2 root root 4096 Dec 28 15:20 conf.d
-rw-r--r-- 1 root root 1007 Nov 19 12:50 fastcgi_params
-rw-r--r-- 1 root root 2837 Nov 19 12:50 koi-utf
-rw-r--r-- 1 root root 2223 Nov 19 12:50 koi-win
-rw-r--r-- 1 root root 5231 Nov 19 12:50 mime.types
lrwxrwxrwx 1 root root 22 Nov 19 12:50 modules -> /usr/lib/nginx/modules
-rw-r--r-- 1 root root 643 Nov 19 12:50 nginx.conf
-rw-r--r-- 1 root root 636 Nov 19 12:50 scgi_params
drwxr-xr-x 2 root root 4096 Jan 26 19:49 sites-available
drwxr-xr-x 2 root root 4096 Jan 26 19:49 sites-enabled
-rw-r--r-- 1 root root 664 Nov 19 12:50 uwsgi_params
-rw-r--r-- 1 root root 3610 Nov 19 12:50 win-utf
drwxr-xr-x 2 root root 4096 Jan 26 19:47 {sites-available,sites-enabled}
Step 3/10 : RUN mkdir -p /etc/nginx/{sites-available,sites-enabled}
Step 4/10 : COPY nginx.conf /etc/nginx/
Step 5/10 : COPY sites-available/*.conf /etc/nginx/sites-available/
Step 6/10 : RUN ln -s /etc/nginx/sites-available/* /etc/nginx/sites-enabled/
---> Running in a2f39a3fd6b3
ln: /etc/nginx/sites-enabled/: No such file or directory
ln: /etc/nginx/sites-enabled/: No such file or directory
ln: /etc/nginx/sites-enabled/: No such file or directory
ln: /etc/nginx/sites-enabled/: No such file or directory
ln: /etc/nginx/sites-enabled/: No such file or directory
ln: /etc/nginx/sites-enabled/: No such file or directory
ln: /etc/nginx/sites-enabled/: No such file or directory
ln: /etc/nginx/sites-enabled/: No such file or directory
The command '/bin/sh -c ln -s /etc/nginx/sites-available/* /etc/nginx/sites-enabled/*' returned a non-zero code: 1
知道为什么这不起作用吗? ^^ 我在 docker 容器外尝试了所有这些命令,它似乎有效
这可以通过使用以下语句将文件直接复制到 sites-enabled
目录来解决:
COPY sites-available/*.conf /etc/nginx/sites-enabled/
您的第 3 步包含一个 bashism:
mkdir -p /etc/nginx/{sites-available,sites-enabled}
使用默认 /bin/sh,这将创建一个目录而不是您想要的两个目录:
$ docker run -it --rm nginx /bin/sh
# ls -al /etc/nginx
total 48
drwxr-xr-x 3 root root 4096 Dec 28 15:20 .
drwxr-xr-x 1 root root 4096 Jan 26 19:46 ..
drwxr-xr-x 2 root root 4096 Dec 28 15:20 conf.d
-rw-r--r-- 1 root root 1007 Nov 19 12:50 fastcgi_params
-rw-r--r-- 1 root root 2837 Nov 19 12:50 koi-utf
-rw-r--r-- 1 root root 2223 Nov 19 12:50 koi-win
-rw-r--r-- 1 root root 5231 Nov 19 12:50 mime.types
lrwxrwxrwx 1 root root 22 Nov 19 12:50 modules -> /usr/lib/nginx/modules
-rw-r--r-- 1 root root 643 Nov 19 12:50 nginx.conf
-rw-r--r-- 1 root root 636 Nov 19 12:50 scgi_params
-rw-r--r-- 1 root root 664 Nov 19 12:50 uwsgi_params
-rw-r--r-- 1 root root 3610 Nov 19 12:50 win-utf
# mkdir -p /etc/nginx/{sites-available,sites-enabled}
# ls -al /etc/nginx
total 56
drwxr-xr-x 1 root root 4096 Jan 26 19:47 .
drwxr-xr-x 1 root root 4096 Jan 26 19:46 ..
drwxr-xr-x 2 root root 4096 Dec 28 15:20 conf.d
-rw-r--r-- 1 root root 1007 Nov 19 12:50 fastcgi_params
-rw-r--r-- 1 root root 2837 Nov 19 12:50 koi-utf
-rw-r--r-- 1 root root 2223 Nov 19 12:50 koi-win
-rw-r--r-- 1 root root 5231 Nov 19 12:50 mime.types
lrwxrwxrwx 1 root root 22 Nov 19 12:50 modules -> /usr/lib/nginx/modules
-rw-r--r-- 1 root root 643 Nov 19 12:50 nginx.conf
-rw-r--r-- 1 root root 636 Nov 19 12:50 scgi_params
-rw-r--r-- 1 root root 664 Nov 19 12:50 uwsgi_params
-rw-r--r-- 1 root root 3610 Nov 19 12:50 win-utf
drwxr-xr-x 2 root root 4096 Jan 26 19:47 {sites-available,sites-enabled}
对于/bin/sh,您需要单独列出它们:
# mkdir -p /etc/nginx/sites-available /etc/nginx/sites-enabled
# ls -al /etc/nginx
total 64
drwxr-xr-x 1 root root 4096 Jan 26 19:49 .
drwxr-xr-x 1 root root 4096 Jan 26 19:46 ..
drwxr-xr-x 2 root root 4096 Dec 28 15:20 conf.d
-rw-r--r-- 1 root root 1007 Nov 19 12:50 fastcgi_params
-rw-r--r-- 1 root root 2837 Nov 19 12:50 koi-utf
-rw-r--r-- 1 root root 2223 Nov 19 12:50 koi-win
-rw-r--r-- 1 root root 5231 Nov 19 12:50 mime.types
lrwxrwxrwx 1 root root 22 Nov 19 12:50 modules -> /usr/lib/nginx/modules
-rw-r--r-- 1 root root 643 Nov 19 12:50 nginx.conf
-rw-r--r-- 1 root root 636 Nov 19 12:50 scgi_params
drwxr-xr-x 2 root root 4096 Jan 26 19:49 sites-available
drwxr-xr-x 2 root root 4096 Jan 26 19:49 sites-enabled
-rw-r--r-- 1 root root 664 Nov 19 12:50 uwsgi_params
-rw-r--r-- 1 root root 3610 Nov 19 12:50 win-utf
drwxr-xr-x 2 root root 4096 Jan 26 19:47 {sites-available,sites-enabled}