How to Solve Error Message docker: Error response from daemon: OCI runtime create failed: starting container process caused “exec: no such file or directory”

Posted on

This article will discuss on how to solve an error message. Actually, the error occurs on executing a command for running an already exist of a docker image. That docker image available by building it through a process. That process is the execution of the following command as follows :

docker build -t image_name . 

The above command is actually a command for building a docker image. The docker image will later on will be useful for running an Apache Webserver. Before building the image, there is a file with the name of Dockerfile for describing the image bulding. The following is the content of the Dockerfile :

FROM centos:7

RUN yum -y install httpd


CMD ["/usr/bin/httpd","-D","FOREGROUND"]                                             

In the above Dockerfile file definition for building the associated docker image, there are several lines exists. The first one is the line to get the base image of CentOS operating system distribution with the version of ‘7’. The next one is the ‘RUN yum -y install httpd’ to execute the command for installing Apache Webserver inside the running container. The next one is the ‘EXPOSE 80’ to inform that the port 80 is available for the host for further usage. It is obvious to expose the port 80 since it is representing the Apache Webserver port service. The last one is to execute the actual file of Apache Webserver so the service will be available.

The execution of the above command for building the docker image container is actually a success. But apparently, upon the execution of that image to build a container for running the associated image, it ends in failure. The following is the error message as an output of the command execution to build a container for running the process inside of it :

user@hostname:~$ docker run -d -p 1234:80 me:centos-apache
docker: Error response from daemon: OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"/usr/bin/httpd\": stat /usr/bin/httpd: no such file or directory": unknown.

Actually, the error message above is very clear. It cannot find the file with the name ‘/usr/bin/httpd/’ for further execution. It is because the file for running the Apache Webserver is not exist in it. The file is in the wrong path. In order to solve the problem, just correct the path. So, the solution is very simple. The following is the solution to handle the problem :

1. Edit the Dockerfile by opening the file with any editor.

2. Change the last line into the following line :

CMD ["/usr/sbin/httpd","-D","FOREGROUND"]

3. Rebuild the image by once again executing the command for building the docker image. In this context, the command is :

docker build -t image_name .

4. Run the image so it will build a new container to run the Apache Webserver service :

user@hostname:~$ docker run -d -p 1234:80 me:centos-apache

5. The previous command is running the container in a detached mode. So, it will still run in the background after the command execution is finish. As an addition, the port 80 is mapped to the host port of 1234. So, in order to prove that the Apache Webserver’s service in the docker container using port 80 is available, just execute ‘localhost:1234’ in the browser from the host.

Leave a Reply