• notice
  • Congratulations on the launch of the Sought Tech site

Resource file path problem during docker installation and deployment

When using docker, you will encounter such a situation, for example, some files such as image resources uploaded by users, it is definitely not appropriate to put them directly in the code, and if you use some soft links to link resources to other directories, you may be wrong When encountering PHP can find the directory, but nginx cannot find the directory, because the default www directory of nginx in the docker container is /usr/share/nginx/html/, and the default directory of php is /var/www, so it will cause Only one of the applications can be loaded when the file is loaded.Of course, this problem can be solved, and the sooner you know this problem, the sooner you can avoid performing some deployment operations and then modify it again.
    The first solution is to unify the default directory names of nginx and php.Note that it must be the path where both containers exist; the second is to mount a directory with the same name when starting nginx and php, so that this directory can be stored The uploaded resources can also allow nginx to access this directory. Of course, the premise here is that the soft link has been used to remove the resource from the code folder.

#Start the complete command of nginx
docker run --name nginx-04007-cn -d -p 80:80 \
-v /data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /data/nginx/conf.d:/etc/nginx/conf.d \
-v /data/nginx/log:/var/log/nginx \
-v /opt/www-data/04007.cn/now_version:/usr/share/nginx/html \
-v /opt/www-data/04007.cn/04007_share_dir:/home/04007_share_dir \
-v /opt/www-data/04007.cn/04007_fix_code:/home/04007_fix_code \
-v /etc/timezone:/etc/timezone \
-v /etc/localtime:/etc/localtime \
#Start php complete command
docker run --name php-04007-cn -d -p 9000:9000 \
-v /opt/www-data/04007.cn/now_version:/var/www \
-v /data/php/php-fpm.conf:/usr/local/etc/php-fpm.conf \
-v /data/php/php-fpm.d:/usr/local/etc/php-fpm.d \
-v /data/php/php:/usr/local/etc/php \
-v /data/php/log:/var/log/php \
-v /opt/www-data/04007.cn/04007_share_dir:/home/04007_share_dir \
-v /opt/www-data/04007.cn/04007_fix_code:/home/04007_fix_code \
-v /etc/timezone:/etc/timezone \
-v /etc/localtime:/etc/localtime \

    In addition, we also encountered a little uncomfortable thing when using docker.For example, we loaded a mirror to build and started a container.At this time, if we want to update the startup command of the container, we must restart a new container.At this time, if it is in the container Some things such as php extensions are installed, I'm sorry, they are all lost, that is, the startup command cannot be changed dynamically! Even some changes that have no other impact, such as adding a mount directory, are quite annoying. But it is not without a solution.Remember to save a new image when you delete the container that is not used but will be used after the expansion and update. In addition, when you need to transfer files between docker and the host, you can use docker copy, but there is no mv cut command, use the following:

#Copy from host to container
docker cp server_path containerID:container_path
#Copy from container to host
docker cp containerID:container_path server_path


Technical otaku

Sought technology together

Related Topic


Leave a Reply