linux - How to change context for Dockerfile using docker composer?
问题描述
I'm developing a CMake project that uses Docker to build on Linux. It's 2 libraries and one executable. One of the libraries is made available in source format only and for which I must provide the CMakeLists.txt file myself.
I can't move or copy that directory to my project folder tree on the root of which is my Dockerfile so I need to find a way to reliably ADD that directory to my container every time I build my project. A solution Google returned is to use docker composer to do so, but I can't get it to work.
This is my docker-composer.yml:
version: '3.8'
services:
dlstreamer:
build:
context: ../
dockerfile: ./PrivacyContainer/Dockerfile
As context
shows, the sources I want are in a directory at the same level as my project directory.
And yet, when I open my folder in a container using Visual Studio code that folder is never copied. What should I be looking for?
解决方案
The docker build documentation page indicates the following :
The context is limited to the current directory (and its children) for security reasons, and to ensure repeatable builds on remote Docker hosts.
This could explain why setting ../
as context doesn't work.
So I think you should launch the docker build command from within your parent directory containing your sources (../), specify the path of your dockerFile using -f and indicate the context Path as .
like this :
docker build -f PrivacyContainer/Dockerfile .
This way, your context includes the directory you want and you'll have access to the files you need for COPY etc.
推荐阅读
- wordpress - 针对特定域的 WordPress 多站点和 301 重定向
- python - any() 的返回值
- python - 编写纸浆约束时遇到问题
- pagination - ngx-owl-carousle-o 分页在 Angular 10 中不起作用
- python - 如何获取数据框行以列出索引号?
- reactjs - 使用 jest 和 redux-mock-store 测试 redux 连接的组件
- firebase - 颤振:从火力基地检索数据
- python - PyCharm 导入与解释器
- flutter - 我想在调用小部件时获得颜色
- node.js - 基于上一个关于 discord.js 依赖的问题