• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

475
Views
¿Cómo crear index.html usando dockerfile?

Estoy tratando de crear una web estática simple usando nginx, y quiero que todo sea creado por Dockerfile, el problema es que cada vez que intento crear un archivo index.html, sale con error, incluso intenté probarlo y su trabajando con "index.htm" pero no con el formato correcto.

 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;"]

y esta es la salida de error:

 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$
about 3 years ago · Santiago Trujillo
4 answers
Answer question

0

debes crear un archivo y puedes usar

COPIAR index.html index.html

comando en Dockerfile para copiar un archivo en la imagen cuando se compila

o usar

echo " " > comando index.html para crear un archivo

about 3 years ago · Santiago Trujillo Report

0

Puede crear un nuevo archivo usando echo :

 RUN echo " " > index.htm
about 3 years ago · Santiago Trujillo Report

0

El archivo ya existe y es propiedad de root:

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

eliminarlo y volver a crearlo:

 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;"]

Tenga en cuenta que, en general, debe combinar varios comandos RUN juntos.

about 3 years ago · Santiago Trujillo Report

0

En su Dockerfile puede usar EJECUTAR RUN {command} como en la línea de comandos.

 RUN mkdir -p /home/foo/ RUN echo "Hello World" > /home/foo/index.html
about 3 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error