Bootstrap FreeKB - Docker - Present working directory
Docker - Present working directory

Updated:   |  Docker articles

The working directory option is used to define the present working directory in a container. For example, if working directory is /tmp, the present working directory in the container would be /tmp.

  • The WORKDIR option can be used in a Dockerfile before a RUN, CMD, ADD, COPY or ENTRYPOINT command
  • The -w or --workdir command line option can be used with the docker command (eg. docker run -w /tmp)
  • The working_dir option can be used in a Docker Compose file (e.g. docker-compose.yml)

As an example, let's say you have a container named foo, and you want to execute command touch foo.txt in the /tmp directory.

store the data in the /var/log directory in the foo container to /usr/local/docker/foo/logs on your Docker server. When creating the image for the foo container, the --volume and --workdir options can be used. Let's break down this command.

  • The docker run command is used
  • The --rm flag is used to remove the container after the Sails app has been created, as we do not need to keep the container that was used to create the Sails app. 
  • The --workdir option is used to set /tmp as the present working directory
  • The foo:latest image is used
  • The bash shell is used to create the foo.txt file in the present working directory
docker run --rm --workdir /tmp foo:latest /bin/bash -c "touch foo.txt"

 

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter ea6b35 in the box below so that we can be sure you are a human.