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.

WORKDIR instruction Dockerfile for Docker Quick Start

  FROM ubuntu
WORKDIR /var/www/html
RUN apt-get update && apt-get install -y nginx
COPY index.html .
ENTRYPOINT ["nginx", "-g", "daemon off;"]
  

build dockerfile

  docker build -t sangam14/workdir-dockerfile  -f dockerfile.workdir .
  

run docker container

  docker run -p 80:80 sangam14/workdir-dockerfile 
  

output

Last updated 24 Feb 2024, 10:56 +0530 . history