Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

context or workdir for docker-compose

I'm learning docker

I need to specify the working directory for a docker image, I think that'll be something like this:

version: '2' services:   test:     build:       context: ./dir 

Now I want to make the image python:onbuild to run on the ./dir, but I dont want to create any Dockerfile inside the ./dir.

The docker-compose manual says nothing about that.

Is it possible? How to do that?

like image 444
Roomy Avatar asked Oct 25 '16 20:10

Roomy


People also ask

What is the context in Docker compose?

context (REQUIRED) context defines 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 MUST be interpreted as relative to the location of the Compose file.

Is Workdir for the host or container?

WORKDIR is your working directory. It only exists in your container.

What does Workdir do in docker?

WORKDIR. The WORKDIR instruction sets a working directory for other Dockerfile instructions, such as RUN , CMD , and also the working directory for running instances of the container image.


2 Answers

I think you're looking for working_dir. Search for "working_dir" in the docker-compose reference.

like image 119
Robin Zimmermann Avatar answered Oct 05 '22 18:10

Robin Zimmermann


You can specify the working directory as follows.

version: '2' services:   test:     build:       context: ./dir     working_dir: /dir 
like image 29
Ian Purton Avatar answered Oct 05 '22 17:10

Ian Purton