我有以下 Dockerfile:
FROM nginx:latest
RUN apt-get update \
&& apt-get -y install openssl \
&& apt-get -y install vim
RUN mkdir -p /etc/nginx/snippets
RUN mkdir -p /etc/openssl
RUN openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/openssl/nginx-selfsigned.key -out /etc/openssl/nginx-selfsigned.crt -subj "/C=US/ST=NY/L=NY/O=ACME/OU=CD/CN=AcmeWPDeveloper"
我沒有收到錯誤訊息,但是當我登錄到容器時,openssl 目錄為空。
我檢查過的:
- 我嘗試創建的所有目錄都存在于新容器中。
- 安裝了openssl。
測驗 /etc/openssl 檔案夾是否存在:
PS C:\Users\me\src\tests\nginx\wordpress-nginx-docker> docker exec -it --user="root" nginx bash
root@59ab746371ba:/# ls -lah /etc/openssl/
total 4.0K
drwxrwxrwx 1 root root 4.0K Oct 27 14:30 .
drwxr-xr-x 1 root root 4.0K Oct 27 14:30 ..
root@59ab746371ba:/# exit
檢查代碼段檔案夾:
root@6ee5da5f4b16:/# ls -lah /etc/nginx/
total 36K
drwxr-xr-x 1 root root 4.0K Oct 27 14:31 .
drwxr-xr-x 1 root root 4.0K Oct 27 14:31 ..
drwxrwxrwx 1 root root 4.0K Oct 27 14:18 conf.d
-rw-r--r-- 1 root root 1007 Sep 7 15:21 fastcgi_params
-rw-r--r-- 1 root root 5.2K Sep 7 15:21 mime.types
lrwxrwxrwx 1 root root 22 Sep 7 15:38 modules -> /usr/lib/nginx/modules
-rw-r--r-- 1 root root 648 Sep 7 15:38 nginx.conf
-rw-r--r-- 1 root root 636 Sep 7 15:21 scgi_params
drwxr-xr-x 2 root root 4.0K Oct 27 14:31 snippets
-rw-r--r-- 1 root root 664 Sep 7 15:21 uwsgi_params
檢查以確保安裝了 openssl 包:
root@6ee5da5f4b16:/# openssl
OpenSSL> ^C
root@6ee5da5f4b16:/#
當我在容器上手動運行命令時,它可以作業:
root@6ee5da5f4b16:/# openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/openssl/nginx-selfsigned.key -out /etc/openssl/nginx-selfsigned.crt -subj "/C=US/ST=NY/L=NY/O=ACME/OU=CD/CN=AcmeWPDeveloper"
Generating a RSA private key
..........................................
.......
writing new private key to '/etc/openssl/nginx-selfsigned.key'
-----
root@6ee5da5f4b16:/# ls -lah /etc/openssl/
total 12K
drwxrwxrwx 1 root root 4.0K Oct 27 14:36 .
drwxr-xr-x 1 root root 4.0K Oct 27 14:31 ..
-rw-r--r-- 1 root root 1.3K Oct 27 14:36 nginx-selfsigned.crt
-rw------- 1 root root 1.7K Oct 27 14:36 nginx-selfsigned.key
root@6ee5da5f4b16:/#
編輯 1
這是使用 Dockerfile 的 docker-compose 檔案:(僅顯示 nginx 節)
nginx:
#image: nginx:${NGINX_VERSION:-latest}
container_name: nginx
ports:
- '8085:8085'
- '443:443'
build: .
volumes:
- ${NGINX_CONF_DIR:-./nginx}:/etc/nginx/conf.d
- ${NGINX_LOG_DIR:-./logs/nginx}:/var/log/nginx
- ${WORDPRESS_DATA_DIR:-./wordpress}:/var/www/html
- ${SSL_CERTS_DIR:-./certs}:/etc/openssl
- ${SSL_CERTS_DATA_DIR:-./certs-data}:/data/openssl
uj5u.com熱心網友回復:
有了這個指令…
volumes:
- ${SSL_CERTS_DIR:-./certs}:/etc/openssl
…/etc/openssl在啟動容器時,您正在使用(空)卷“覆寫”已經存在的影像(其中包含檔案)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/339933.html
