I am trying to mount a folder from the host as a volume to the container. I am wondering at what step is this mounting process done - I would expect it to be during the build phase, but it seems that my folder is not mounted.
The folder structure:
-> app
|-> requirements.txt
- docker
|-> web
|-> Dockerfile
-> docker-compose.yml
docker-compose.yml contains the following:
version: '2'
services:
web:
build: ./docker/web
volumes:
- './app:/myapp'
The docker file of the container:
FROM ubuntu:latest
WORKDIR /myapp
RUN ls
I am mounting the app directory from the host into /myapp inside the container, the build process sets the working directory and runs ls to see the content and I am expecting my reuqiremetns.txt file to be there.
What am I doing wrong?
docker-compose v1.16.1, docker v1.16.1. I am using docker for windows.
Your requirements.txt file isn't copied into the image at build time because it's not picked up by the context and requirements.txt is not present at build time.
Volumes are mounted at container creation time, not at build time. If you want your file to be available inside your Dockerfile (e.g. at build time) you need to include it in the context and COPY it to make it available.
From the Docker documentation here: https://docs.docker.com/engine/reference/builder/
The first thing a build process does is send the entire
context (recursively) to the daemon
It's two issues:
requirements.txt is not not available at build timels command (COPY ./app/requirements.txt /myapp/)If can change your directory structure to make requirements.txt available at build time, and add a COPY command to your Dockerfile before you run your ls you should see the behavior you expect during the build.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With