The Docker can mount the folder in host OS to share with container. This article says check points if this function doesn’t work fine.
The running environment of this article is macOS Catalina 10.15.
When the host OS is macOS, the privacy settings also needed to be checked.
I have been using the web server which is running on the docker container to develop. The content files are in the folder which is shared with the container, because I want to edit them quickly.
The configuration file of the Docker Composer is following:
version: "3" services: nginx: build: . ports: - 80:80 volumes: - ./content_home:/usr/share/nginx/html
I ran this container and access it, but the web browser said
404 Not Found error.
When I move the folder contains files including
docker-compose.yml to another location, the container works fine.
What You Should Check
This is a checklist for this situation.
- Can you see the contents of
./content_homeexists in host OS?
- Does docker has rights such as permission to the
./content_homein host OS?
Check the Container
/usr/share/nginx/html in the container.
$ docker container exec testserver_nginx_1 ls /usr/share/nginx html
html is output so the
html is exists. Next, check the contents.
$ docker container exec testserver_nginx_1 ls /usr/share/nginx/html ls: cannot open directory '/usr/share/nginx/html': Operation not permitted
I couldn’t access to the contents of the folder, it seems that the docker doesn’t have the permission to the shared folder.
Check the Host
Check the folder is exists and a permission. It is easy with the Finder. Select the folder and choose “Get Info” from the “File” menu. Check the “Sharing & Permissions”.
It is fine if me is “Read & Write”, “staff” is “Read only” and “everyone“ is “Read only”.
And my OS, no problem.
On macOS, the following three folders need to be given permission for each application.
When you first time to access these folders, the macOS will prompt to get the permission. If you didn’t allow in this dialog, the application can’t to access.
You can check or change the configuration by following steps:
- Choose “System Preferences…” from Apple menu.
- Click the “Security & Privacy”.
- Select the “Privacy” tab.
- Select the “Files and Folders”.
The checkbox of the “Desktop Folder” was unchecked.
I worked in the Desktop folder.
I don’t remember, but they seemed to have removed it.
- Representative of RK Kaihatsu. I am a professional developer specializing in macOS Apps, iOS Apps, SDKs and middleware development. I often use ObjC, Swift and C++. Based on development experience, I provide e-learning contents, technical books and technical guidance. I am also a technical seminar instructor, in-house training instructor, and administrative / local goverment staff training instructor.