• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

489
Vistas
How to create index.html using dockerfile?

I'm trying to create a simple static web using nginx, and want to have everything created by Dockerfile, the problem is whenever I tried to create an index.html file, it comes out with error, I even tried to test it and its working with "index.htm" but not with the correct format.

FROM centos:7
#update and install nginx section
RUN yum update -y
RUN yum install -y epel-release
RUN yum install -y nginx
#create path and add index.html
WORKDIR /usr/share/nginx/html

#this one working with no issue 
RUN touch index.htm
#this one will get failed
RUN touch index.html

EXPOSE 80/tcp

CMD ["nginx", "-g", "daemon off;"]

and this is the error output:

majid@DESKTOP-39CBKO0:~/nginx_simple_web$ docker build -t simple-web:v1 .
[+] Building 3.8s (11/11) FINISHED
 => [internal] load build definition from Dockerfile                                                          0.0s
 => => transferring dockerfile: 381B                                                                          0.0s
 => [internal] load .dockerignore                                                                             0.0s
 => => transferring context: 2B                                                                               0.0s
 => [internal] load metadata for docker.io/library/centos:7                                                   3.4s
 => [auth] library/centos:pull token for registry-1.docker.io                                                 0.0s
 => [1/7] FROM docker.io/library/centos:7@sha256:9d4bcbbb213dfd745b58be38b13b996ebb5ac315fe75711bd618426a630  0.0s
 => CACHED [2/7] RUN yum update -y                                                                            0.0s
 => CACHED [3/7] RUN yum install -y epel-release                                                              0.0s
 => CACHED [4/7] RUN yum install -y nginx                                                                     0.0s
 => CACHED [5/7] WORKDIR /usr/share/nginx/html                                                                0.0s
 => CACHED [6/7] RUN touch index.htm                                                                          0.0s
 => ERROR [7/7] RUN touch index.html                                                                          0.4s
------
 > [7/7] RUN touch index.html:
#11 0.357 touch: cannot touch 'index.html': No such file or directory
------
executor failed running [/bin/sh -c touch index.html]: exit code: 1
majid@DESKTOP-39CBKO0:~/nginx_simple_web$
over 3 years ago · Santiago Trujillo
4 Respuestas
Responde la pregunta

0

you should create a file and you can use

COPY index.html index.html

command into Dockerfile to copy a file into image when build

or use

echo " " > index.html command to create a file

over 3 years ago · Santiago Trujillo Denunciar

0

You can create a new file using echo:

RUN echo " " > index.htm
over 3 years ago · Santiago Trujillo Denunciar

0

The file already exists and is owned by root:

RUN ls -al index.html
 ---> Running in 27f9d0ae6240
lrwxrwxrwx 1 root root 25 Dec 23 12:08 index.html 
-> ../../doc/HTML/index.html

remove it and re-create it:

FROM centos:7
#update and install nginx section
RUN yum update -y
RUN yum install -y epel-release
RUN yum install -y nginx
RUN yum install -y vim
#create path and add index.html
WORKDIR /usr/share/nginx/html

RUN rm index.html
RUN touch index.html

EXPOSE 80/tcp

CMD ["nginx", "-g", "daemon off;"]

Do note that you should, in general, combine multiple RUN commands together.

over 3 years ago · Santiago Trujillo Denunciar

0

In your Dockerfile you can use RUN {command} like in the commandline.

RUN mkdir -p /home/foo/
RUN echo "Hello World" > /home/foo/index.html
over 3 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda