我们有两个应用程序在系统中运行,一个来自docker,另一个直接在系统中运行。我们需要使用name = input('What\'s your name: ')
print(f'Welcome {name} to the question challenge')
correct_answers = 0
print('Question number 1 (answer YES or NO)')
answer1 = input('My favorite color is purple:')
if answer1.lower() in {'yes', 'si'}:
print(f'You are right')
correct_answers += 1
print(correct_answers)
elif answer1.lower() == 'no':
print('You got it wrong')
else:
print('Please answer with YES or NO')
API来访问容器应用程序中的系统应用程序
我们正在使用localhost:8082
在node JS
主页上运行Windows 10
容器,端口为Docker toolbox
,并且在容器外部运行应用意味着直接从8042的机器上运行,我们需要访问节点容器中的这个localhost:8042
API,我们如何使用Docker version 19.03.1
运行cmd:
docker container run -p --net=host -it -v `pwd`:/usr/src/app --rm --name server server/windows:v1
Error: Connection refuesed 127.0.0.1:8042
,同时运行docker容器。
完全错误:
(node:80) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:8042
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1137:16)
(node:80) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection,
use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:80) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will
terminate the Node.js process with a non-zero exit code.
Dockerfile
FROM node:12
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
# Specify port app runs on
EXPOSE 5000
# Run the app
CMD [ "npm", "run", "dev"]
答案 0 :(得分:-1)
错误:运行docker容器时连接驳回127.0.0.1:8042。
这是因为主机上正在使用端口8042,因此在运行容器时无法映射该端口。
相反,您应该在运行容器时尝试--net=host
。
docker container run --net=host -it -v `pwd`:/usr/src/app --rm --name server server/windows:v1
阅读this,了解有关Docker的--net=host
属性的更多信息。