PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, October 18, 2022

[FIXED] When I use Docker, I directly bind a file between the host and the container,but the two files cannot be synchronized

 October 18, 2022     docker, docker-volume     No comments   

Issue

I start a docker container with the followings:

cd /root 

docker run -it -d --privileged=true --name nginx nginx 

rm -fr dockerdata 

mkdir dockerdata 

cd dockerdata 

mkdir nginx 

cd nginx 

docker cp nginx:/usr/share/nginx/html . 

docker cp nginx:/etc/nginx/nginx.conf . 

docker cp nginx:/etc/nginx/conf.d ./conf 

docker cp nginx:/var/log/nginx ./logs 

docker rm -f nginx 

cd /root 

docker run -it -d -p 8020:80 --privileged=true --name nginx \
-v /root/dockerdata/nginx/html:/usr/share/nginx/html \
-v /root/dockerdata/nginx/nginx.conf:/etc/nginx/nginx.conf \
-v /root/dockerdata/nginx/conf:/etc/nginx/conf.d \
-v /root/dockerdata/nginx/logs:/var/log/nginx \
nginx

"docker inspect nginx" is followings

HostConfig-Binds

The bound directory can be synchronized, but directly bound files like "nginx. conf" cannot be synchronized. When I modify the "nginx. conf" in the host, the "nginx. conf" in the container does not change.

I want to know why this happens and how I can directly bind a single file between the host and the container.##


Solution

why this happens

Mount bind mounts the file to inode. The nginx entrypoint executes in https://github.com/nginxinc/docker-nginx/blob/ed42652f987141da65bab235b86a165b2c506cf5/stable/debian/30-tune-worker-processes.sh :

sed -i.bak

sed creates a new file, then moves the new file to the old one. The inode of the file changes, so it's no longer mounted inode.

how I can directly bind a

It is bind. Instead, you should consider re-reading nginx docker container documentation on how to pass custom config to it:

-v /host/path/nginx.conf:/etc/nginx/nginx.conf:ro
                                              ^^^

Which does skip sed at https://github.com/nginxinc/docker-nginx/blob/ed42652f987141da65bab235b86a165b2c506cf5/stable/debian/30-tune-worker-processes.sh#L12 .



Answered By - KamilCuk
Answer Checked By - Mildred Charles (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing