I am trying to dockerize a PHP application. In the dockerfile, I download the archive, extract it, etc.
Everything works fine. However, if a new version gets released
The way that worked for me is to use a bind
mount
version: "3.7"
services:
app:
image: app:latest
volumes:
- type: bind
source: ./sourceFile.yaml
target: /location/targetFile.yaml
Thanks mike breed for the answer over at: Mount single file from volume using docker-compose
You need to use the "long syntax" to express a bind
mount using the volumes
key: https://docs.docker.com/compose/compose-file/#long-syntax-3
In windows, if you need the a ${PWD} env variable in your docker-compose.yml you can creat a .env file in the same directory as your docker-compose.yml file then insert manualy the location of your folder.
CMD (pwd_var.bat) :
echo PWD=%cd% >> .env
Powershell (pwd_var.ps1) :
$PSDefaultParameterValues['Out-File:Encoding'] = 'utf8'; echo "PWD=$(get-location).path" >> .env
There is more good features hear for docker-compose .env variables:
https://docs.docker.com/compose/reference/envvars/ especially for the COMPOSE_CONVERT_WINDOWS_PATHS
env variable that allow docker compose to accept windows path with baskslash "\"
.
When you want to share a file on windows, the file must exist before sharing it with the container.
I had the same issue, docker-compose was creating a directory instead of a file, then crashing mid-way.
what i did :
run the container without mapping the file
copy the config file to the host location :
docker cp containername:/var/www/html/config.php ./config.php
remove the container (docker-compose down)
put the mapping back and remount up the container
docker compose will find the config file, and will map that instead of trying to create a directory.
For anyone using Windows container like me, know that you CANNOT bind or mount single files using windows container.
The following examples will fail when using Windows-based containers, as the destination of a volume or bind mount inside the container must be one of: a non-existing or empty directory; or a drive other than C:. Further, the source of a bind mount must be a local directory, not a file.
net use z: \\remotemachine\share
docker run -v z:\foo:c:\dest ...
docker run -v \\uncpath\to\directory:c:\dest ...
docker run -v c:\foo\somefile.txt:c:\dest ...
docker run -v c:\foo:c: ...
docker run -v c:\foo:c:\existing-directory-with-contents ...
It's hard to spot but it's there
Link to the Github issue regarding mapping files into Windows container
I have same issue on my Windows 8.1
It turned out that it was due to case-sensitivity of path.
I called docker-compose up
from directory cd /c/users/alex/
and inside container a file was turned into directory.
But when I did cd /c/Users/alex/
(not Users capitalized) and called docker-compose up
from there, it worked.
In my system both Users dir and Alex dir are capitalized, though it seems like only Users dir matter.
I had the same issue on Windows, Docker 18.06.1-ce-win73 (19507)
.
Removing and re-adding the shared drive via the Docker settings panel and everything worked again.