我创建了一个带有Docker设置的Reactjs应用程序。我用的是Windows 10。构建完成后,容器只是重新启动,在日志中产生错误:
码头工人形象
日志图片
浏览器图像yarn run v1.22.5
error Command "installr" not found.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
: not foundotup.sh: line 3:
/var/www/bootup.sh: line 11: syntax error: unexpected end of file (expecting "then")
Dockerfile
# pull official base image
FROM node:12.20.0-alpine3.10
WORKDIR /var/www
COPY package.json /var/www/
RUN yarn install
COPY . /var/www/
# Install create-react-app package
RUN yarn global add react-scripts
EXPOSE 3000
ADD ./bootup.sh /var/www
RUN cd /var/www
RUN chmod +x /var/www/bootup.sh
docker-compose.yml
version: '3.7'
services:
frontend:
build: .
restart: unless-stopped
tty: true
working_dir: /var/www/
ports:
- '3002:3000'
volumes:
- '.:/var/www'
- /var/www/node_modules
environment:
- CHOKIDAR_USEPOLLING=true yarn start
command: /var/www/bootup.sh ${SSL_ON}
bootup.sh
# Install Dependencies
yarn install
# Start the react app
if [ "$1" == "true" ]
then
yarn start-https
else
yarn start
fi
我尝试重新启动它,杀死容器,再次克隆存储库,但问题仍然发生。
我用另一台笔记本电脑在Ubuntu上克隆了这个repo,这些错误都没有发生,只有在windows上。如果有人知道这是什么意思,那将是一个很大的帮助。
我根据@HansKilian关于行尾的评论解决了这个问题。关于如何将bootup.sh
文件转换为正确的unix风格的行结尾,我遵循了这个链接:https://support.nesi.org.nz/hc/en-gb/articles/218032857-Converting-from-Windows-style-to-UNIX-style-line-endings