How to create a folder in Docker

How to create a folder in Docker

To create a folder in docker or a file create a directory for the build context and cd into it. You can use the classic mkdir command to create a folder in Docker.

Write “hello” into a text file named hello and create a Dockerfile that runs cat on it. Build the Image from within the build context.

Commands to Create a folder in Docker

mkdir myproject && cd myproject
echo "hello" > hello
echo -e "FROM busybox\nCOPY /hello /\nRUN cat /hello" > Dockerfile
docker build -t helloapp:v1 .

Alternatively, you can also try the below commands to create a folder or file in Docker

# create a directory to work in
mkdir example
cd example

# create an example file
touch somefile.txt

docker build -t myimage:latest

Apr 6, 2022