ERROR: Cannot locate specified Dockerfile: Dockerfile-dev - docker

Here the structure of my project(debug_project) folder.
This is my Docker compose command.
After executing the command, I get this error.
Here is my docker-compose-dev.yml file.
This is the link I have followed.
How to resolve this error?

It is assumed that the Dockerfile is present relative to the folder specified in the context field.
So you have two choices either move the Dockerfile inside the app directory or have an absolute path to the Dockerfile.
Something like
foo:
build:
context: app
dockerfile: ${PWD}/Dockerfile-dev

The context specifies the path to the directory containing the docker file. You need to move the Dockerfile-dev into that directory.
https://docs.docker.com/compose/compose-file/#build
Either a path to a directory containing a Dockerfile, or a url to a git repository.
When the value supplied is a relative path, it is interpreted as relative to the location of the Compose file. This directory is also the build context that is sent to the Docker daemon.

Related

Can not use absolute path when COPY, Why? [duplicate]

I have following line in my dockerfile
COPY /root/url.net/volumes/persistent/url/root /usr/share/nginx/html
When I try to build the image with docker-compose I get
Service 'frontend' failed to build: lstat
/root/url.net/volumes/persistent/url/root: no such file or
directory
I can cd from anywhere to /root/url.net/volumes/persistent/url/root with no problem on my machine.
How can I specify the absolute path of the folder in the dockerfile?
The absolute path of your resources refers to an absolute path within the build context, not an absolute path on the host. So all the resources must be copied into the directory where you run the docker build and then provide the path of those resources within your Dockerfiles before building the image. (This refers to the location where you run your Dockerfile)
There is a closed issue for this as well.
You can't. You have to copy/hardlink the files/folders inside the directory where you build the docker image.

Is there a way to copy the contents of the directory into the Docker container?

Pretty much the title says it all.
I know I can copy the file (from the host) into a docker container.
I also know I can copy the directory into a docker container.
But how to copy the contents of a directory (preserving all subdirectories) into a directory in a docker container?
On my host I have a directory called src. On the docker container I have a directory /var/www/html. That src has both files and directories. I need all of them to be copied (with the command) into the container; not bound, not mounted, but copied.
It sounds like a trivial operation, but I've tried so many ways and couldn't find anything online that works! Ideally, it would be best if that copy operation would work every time I run the docker-compose up -d command.
Thanks in advance!
I found the solution. There is a way of specifying the context directory explicitly; in that case the dockerfile also need to be specified explicitly too.
In the docker-compose.yml one should have the following structure:
services:
php:
build:
context: .
dockerfile: ./php/Dockerfile
In this case the src is "visible" because it is inside the context! Then in that Dockerfile the COPY command will work!
Update: There is another way to achieve this via the command as well. However for me it started to work when I've added the ./ at the end. So the full command is:
docker cp ./src/./ $(docker-compose ps|grep php|awk '{print $1}'):/var/www/html/

docker compose not finding my files

Docker is telling me it cant find the specified file. Is my context wrong? My folder structure is as follows.
root
- docker
- docker-compose-service.yml
- service
- DockerFile
Nuget.config
Inside my docker-compose-service.yml file I have
build:
context: .
dockerfile: ../service/DockerFile
I run from the root folder the following command
docker-compose -f docker/docker-compose-service.yml up --build
It can find the Dockerfile as it runs the code but fails on a line inside the dockerFile which is
COPY NuGet.config .
The error is
failed to build: COPY failed: stat /var/lib/docker/tmp/docker-builder408021827/NuGet.config: no such file or directory
What am I doing wrong? I played around with the context and dockerFile location but then it couldn't find the DockerFile
Hmm so if I run the command from the docker folder and change the docker-compose-service.yml file to be
context: ../
dockerfile: service/DockerFile
That seems to work
Usually, from what I can see in projects, context's are build in a different way. You should reorganize your project like this:
root
- docker-compose.yml
- service
- Dockerfile
- Nuget.config
The build in the compose file would look like this afterwards:
build: ./service
And you run it like:
docker-compose up --build
The path specified in your docker file sets the context as the parent folder of the compose file.
In order to make it work, you need to either:
Change the context to .
Change the path to NuGet.config to also contain the current folder name: root/NuGet.config
I would recommend the first approach as from your question I don't see any reason you would want to refer to the parent folder.

Move docker setup into folder

I have a docker-compose setup something like:
/
- sources/
- docker-compose.yml
- Dockerfile
- .dockerignore
- many more files
The Dockerfile contains instructions including a COPY command of the sources.
Because of all the different tools, including multiple docker setups, I'd like to organise it a bit, by either moving all files to a folder:
/
- sources/
- docker/
- many more files
or leaving just the docker-compose.yml file outside of this folder:
/
- sources/
- docker/
- many more files
I'd like to do this because:
It cleans up the project folder
I currently have multiple docker setups in the project folder, moving them to seperate folders allows for a more clear and/or precise setup (e.g. multiple dockerignore files)
Currently I am running into some issues which do make sense, such as:
COPY failed: Forbidden path outside the build context: ../sources/
Is it possible to achieve this setup? Thanks!
Inside the Dockerfile, you cannot access files that are outside the build context. In your case the build context is the directory containing the Dockerfile.
You can change the build context inside the composefile.
Below is an example where the composefile is at the root and Dockerfile is under docker folder:
version: '3'
services:
test:
build:
context: .
dockerfile: docker/Dockerfile
In this case, inside the Dockerfile the file paths should be set relative to the context.
COPY sources sources
For dockerignore:
As specified in the docs for .dockerignore file:
Before the docker CLI sends the context to the docker daemon, it looks for a file named .dockerignore in the root directory of the context
Thus you need to add the dockerignore file to the root of the context.
You can't use that within the Dockerfile however you should be able to make it work using a .env file and pulling it in from there.
https://docs.docker.com/compose/env-file/
You could try something like:
.env
SOURCE_PATH=../sources/
Dockerfile
COPY ${SOURCE_PATH}/myfile /some/destination

Filesystem changes inside Docker container aren't displayed onto the host filesystem

I'm using the Docker and docker-compose to run my app inside a container. Here is my docker-compose.yml:
version: '2'
services:
omsevents:
build:
context: ./omsevents
volumes:
- "../oms-events:/usr/app/oms-events"
- "../oms-events/assets:/usr/app/oms-events/assets"
The thing is, my app is a server and one of the things it does is file upload. When I upload a file it is created inside a container (I can bash inside the container and check and it's there, in /usr/app/oms-events/assets), bit it's not created on the host filesystem (the ../oms-events/assets/ folder is empty).
What can be the issue?
According to the documentation of Docker Compose:
You can mount a relative path on the host, which will expand relative to the directory of the Compose configuration file being used. Relative paths should always begin with . or ..
So you can try moving the docker-compose file into the context directory and remove the context clause from the build section, leaving it just build: . (or wherever your Dokerfile is). Then just fix the relative paths of the volumes or try with absolute ones.

Resources