《微軟官網(wǎng)Windows 上的 Docker 引擎幫助文檔》
以Nginx為例
拉取Nginx鏡像
docker pull nginx:1.23.1
先啟動(dòng)Nginx,然后把Nginx的配置文件復(fù)制到Windows
docker run --name=nginx-1.23.1 -d -p 80:80 nginx:1.23.1
把Nginx的配置文件復(fù)制到Windows
注意:Windows的盤符是小寫的,以及目錄直接是用反斜杠的!(我掉這坑里好久?。。。?mark hidden color="red">文章來源:http://www.zghlxwxcb.cn/news/detail-707594.html
docker cp nginx-1.23.1:/etc/nginx/nginx.conf d:\software\nginx\nginx.conf
docker cp nginx-1.23.1:/usr/share/nginx/html d:\software\nginx\html
修改宿主機(jī)的nginx.conf配置文件
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
location / {
#root html;
root /usr/share/nginx/html; # nginx工作目錄是容器的而非宿主機(jī)
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
include /etc/nginx/conf.d/*.conf;
}
刪除nginx容器
docker rm -f nginx-1.23.1
重啟啟動(dòng)一個(gè)新的Nginx容器
docker run -p 80:80 --name nginx-1.23.1 --privileged=true --restart=always -v d:\software\nginx\html:/usr/share/nginx/html -v d:\software\nginx\log:/var/log/nginx -v d:\software\nginx\nginx.conf:/etc/nginx/nginx.conf -d nginx:1.23.1
訪問localhost
文章來源地址http://www.zghlxwxcb.cn/news/detail-707594.html
到了這里,關(guān)于Docker Desktop使用宿主機(jī)Windows的配置文件持久化存儲(chǔ)數(shù)據(jù)的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!