Home > Net >  setting correct WORKDIR in a multi-stage build for docker
setting correct WORKDIR in a multi-stage build for docker

Time:05-16

I wish to build a docker image that can start a container where I can use both node version 14 and lz4. The dockerfile I have so far is:

FROM node:14-alpine

WORKDIR /app

RUN apk update
RUN apk add --upgrade lz4

node --version and lz4 --help seem to run ok with the docker run command - but I wanted to ask whether there is a specific WORKDIR I should be using in the dockerfile to follow any best practices (if any exist), or does it not matter what I set the WORKDIR to? Note I'm not sure of all my future requirements, but I may need to use this image to build other images in the future, so I want to ensure WORKDIR is set appropriately.

CodePudding user response:

WORKDIR should be set to set the working directory for the subsequent docker commands in dockerfile, which makes things a little easy to understand as the paths will be relative to the working directory.

By default, / root dir is the set working directory. Without setting any other workdir, all the commands can have absolute paths which make it even more easy to understand.

CodePudding user response:

It doesn't really matter much. Besides, you could always change it for your future builds.

  • Related