Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify working directory for ENTRYPOINT in Dockerfile

The Docker image (Windows-based) includes an application directory at C:\App. Inside that directory reside several sub-folders and files, including a batch file called process.bat. The Dockerfile (used to build the image) ends like this:

ENTRYPOINT [ "C:\\App\\process.bat" ] 

When I instantiate this image using the command: docker run company/app, the batch file runs, but it fails at the point where other files under C:\App are referenced. Essentially, the working directory is still C:\ from the Docker container's entry-point.

Is there a way to set the working directory within the Dockerfile? Couple of alternatives do exist:

  • Add -w C:\App to the docker run
  • In the batch file, I can add a line at the beginning cd /D C:\App

But is there a way to specify the working directory in the Dockerfile?

like image 680
Web User Avatar asked Aug 16 '17 19:08

Web User


People also ask

How do I change the directory in Dockerfile?

Easy ! Just use the WORKDIR command to change the directory you want to. Any other commands you use beyond this command will be executed in the directory you have set. It is also a better practice to make use of WORKDIR in docker.

What is working directory in Dockerfile?

The WORKDIR command is used to define the working directory of a Docker container at any given time. The command is specified in the Dockerfile. Any RUN , CMD , ADD , COPY , or ENTRYPOINT command will be executed in the specified working directory.


1 Answers

WORKDIR /App is a command you can use in your dockerfile to change the working directory.

like image 69
Ayushya Avatar answered Sep 28 '22 01:09

Ayushya