Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot execute RUN mkdir in a Dockerfile

Tags:

docker

This is an error message I get when building a Docker image:

Step 18 : RUN mkdir /var/www/app && chown luqo33:www-data /var/www/app
---> Running in 7b5854406120 mkdir: cannot create directory '/var/www/app': No such file or directory

This is a fragment of Dockerfile that causes the error:

FROM ubuntu:14.04
RUN groupadd -r luqo33 && useradd -r -g luqo33 luqo33

<installing nginx, fpm, php and a couple of other things>

RUN mkdir /var/www/app && chown luqo33:www-data /var/www/app
VOLUME /var/www/app
WORKDIR /var/www/app

mkdir: cannot create directory '/var/www/app': No such file or directory sound so nonsensical - of course there is no such directory. I want to create it. What is wrong here?

like image 904
luqo33 Avatar asked Oct 01 '22 08:10

luqo33


People also ask

What is run mkdir in Dockerfile?

The command RUN mkdir -p /var/www/new_directory allows you to create a directory named new_directory inside the Docker file system that we will eventually build using an image built using the above Docker file.

How do I run a command in Dockerfile?

CMD is the command the container executes by default when you launch the built image. A Dockerfile will only use the final CMD defined. The CMD can be overridden when starting a container with docker run $image $other_command .


2 Answers

The problem is that /var/www doesn't exist either, and mkdir isn't recursive by default -- it expects the immediate parent directory to exist.

Use:

mkdir -p /var/www/app

...or install a package that creates a /var/www prior to reaching this point in your Dockerfile.

like image 231
Charles Duffy Avatar answered Oct 09 '22 01:10

Charles Duffy


When creating subdirectories hanging off from a non-existing parent directory(s) you must pass the -p flag to mkdir ... Please update your Dockerfile with

RUN mkdir -p ... 

I tested this and it's correct.

like image 73
Kostikas Avatar answered Oct 09 '22 02:10

Kostikas