为我的CRA应用程序创建docker映像时遇到问题。这是我用于生产环境的Dockerfile:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<title>JasonTravis</title>
<meta content="Jason Travis Portfollio" name="Jason Travis">
<meta content="" name="Jason Travis-Baker">
<link href="css/styles.css" rel="stylesheet">
<link href="css/bootstrap.css" rel="stylesheet">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet">
</head>
<body>
<style>
body{ background-color: #FFFFFF; }
a {text-decoration:none}
a:link, a:visited, a:active { color: white; text-decoration: none}
a:hover { color: black; opacity: 0.4}
</style>
<!-- Main Navigation -->
<nav>
<ul>
<a href="about.html">about</a>
<a href="Porfolio.html">porfolio</a>
<li>
<a href="https://www.instagram.com/jaytravisdesign/" target="_blank"><i aria-hidden="true" class="fa fa-instagram"></i></a>
</li>
<li>
<a href="https://twitter.com/JayTravisDesign" target="_blank"><i aria-hidden="true" class="fa fa-twitter"></i></a>
</li>
<li>
<a href="mailto:jaytravisdesign@gmail.com" target="_blank"><i aria-hidden="true" class="fa fa-envelope-o"></i></a>
</li>
<li>
<a href="https://www.linkedin.com/in/jasontravis-baker1091985/" target="_blank"><i aria-hidden="true" class="fa fa-linkedin"></i></a>
</li>
<li>
<a href="" target="_blank"><i aria-hidden="true" class="fa fa-slack"></i></a>
</li>
</ul>
</nav>
<div class="coderh1">
<h1 class="coder"><span>< Coder ></span></h1>
</div><!-- Main Text -->
<div class="sp-container">
<div class="sp-content">
<div class="sp-globe"></div>
</div>
<h2 class="frame-5"><span>UI</span>
<span style="color:Lightblue">/ UX</span>
<span>Designer</span></h2>
</div>
<div class="scroll-down"></div>
<section class="sec1"></section>
<section class="content">
<h6>Current Projects</h6>
</section>
<div id="images">
<a href="https://www.raybakercoaching.com/"><img alt="raybakercoaching.com" border="0" class="rbcoaching" src="raybakerteamultimate.png"></a> <a href="https://www.raybakercoacking.com/" target="_blank"><img alt="raybakercoaching.com" border="0" class="rbcoaching" src="raybakerteamultimate.png"></a>
</div>
<!-- Return to Top -->
<a href="↑:" id="return-to-top"><i class="fa fa-long-arrow-up" aria-hidden="true"></i></a> <!-- Footer -->
<footer class="footer">
© Jay Travis Design 2019
</footer><!--JS-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/2.0.2/anime.min.js">
</script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js">
</script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
<script src="js/jquery-3.3.1.min.js">
</script>
<script src="js/scripts.js">
</script>
</body>
</html>
# base image
FROM node:10.13.0
# set working directory
WORKDIR /usr/src/app
# install and cache app dependencies
COPY package.json yarn.lock ./
RUN yarn
COPY . ./
# RUN yarn cache clean
RUN yarn build
# Stage 2 - the production environment
FROM nginx:latest
# COPY build /usr/share/nginx/html
COPY ./build /var/www
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
进程成功运行到第8步,并返回以下错误:docker build
根据我的理解,该错误告诉我毕竟不是创建build文件夹,因此无法移动它。
答案 0 :(得分:1)
此Dockerfile
使用multi-stage build。第八步-COPY ./build /var/www
失败,因为它试图将nginx映像中的build
目录(第二阶段,而不是运行yarn build
的第一阶段)复制到/var/www
,这不存在。
要使其正常运行,请指定应从第一阶段(运行build
的第一阶段复制yarn build
目录。为此,请进行以下更改:
FROM node:10.13.0 AS base
来命名基础阶段(此处可以使用任何名称代替base
)。COPY ./build /var/www
更改为COPY --from=base ./build /var/www
,表示我们要从第一阶段而不是第二阶段复制build
目录。