c++ - 在 arm64 docker 容器中运行 c++ 应用程序时出现错误“getsockopt level=1 optname=20 not yet supported”
问题描述
我使用实现 HTTPS POST 请求的 Poco 库创建了以下 c++ 程序。
#include <Poco/Net/HTTPClientSession.h>
#include <Poco/Net/HTTPRequest.h>
#include <Poco/Net/HTTPResponse.h>
#include <Poco/Net/HTTPSClientSession.h>
#include <Poco/StreamCopier.h>
#include <Poco/URI.h>
#include <Poco/File.h>
#include <iostream>
#include <string>
#include <stdio.h>
using Poco::Net::HTTPSClientSession;
using Poco::Net::HTTPClientSession;
using Poco::Net::HTTPRequest;
using Poco::Net::HTTPResponse;
using Poco::Net::HTTPMessage;
using Poco::URI;
using Poco::File;
using namespace std;
using namespace Poco;
using namespace Poco::Net;
int main()
{
try
{
URI uri = URI("https://example.com/login");
string path(uri.getPathAndQuery());
if (path.empty())
path = "/";
Context::Ptr ctx = new Context(Context::TLSV1_2_CLIENT_USE, "", "", "", Context::VERIFY_NONE, 9, true, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
HTTPSClientSession session(uri.getHost(), uri.getPort(), ctx);
HTTPRequest request(HTTPRequest::HTTP_POST, path, HTTPMessage::HTTP_1_1);
std::string body("this is a random request body\r\n0\r\n");
request.setContentLength((int) body.length());
session.sendRequest(request) << body;
HTTPResponse response;
istream &is = session.receiveResponse(response);
string responseStr;
StreamCopier::copyToString(is, responseStr);
cout << "response is " << responseStr << endl;
}
catch (Poco::Exception& exc)
{
cout << "Poco Exception occured during https request." << endl;
cout << "message: " << exc.message() << endl;
}
}
当我为我的 Ubuntu 20.04 amd64 架构构建它时,它工作正常并且响应是正确的
response is <?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>404 - Not Found</title>
</head>
<body>
<h1>404 - Not Found</h1>
<script type="text/javascript" src="//wpc.75674.betacdn.net/0075674/www/ec_tpm_bcon.js"></script>
</body>
</html>
之后,我为 arm64 arch 构建了它,并尝试根据我在 Dockerfile 之后构建的映像在 docker 容器中运行它:
FROM arm64v8/ubuntu:20.04
WORKDIR /opt/myapp
ENV DEBIAN_FRONTEND=noninteractive
COPY myapp .
RUN apt-get clean
RUN apt-get update
RUN apt-get install libssl-dev nano iputils-ping curl -y
# cleanup
RUN apt-get -qy autoremove
RUN echo "/opt/myapp/libs" >> /etc/ld.so.conf && \
ldconfig
EXPOSE 2
EXPOSE 8022
EXPOSE 443
EXPOSE 80
CMD ["bash"]
之后我使用以下命令运行容器
docker run -v /usr/bin/qemu-aarch64-static:/usr/bin/qemu-aarch64-static -i -t --platform arm64 myapp_image
程序运行到session.sendRequest(request) << body;
终端给出以下错误的行:
getsockopt level=1 optname=20 not yet supported
捕获的异常是:
Net Exception: Operation not supported
另一方面,当我在容器内给出命令时:
curl -d '{json}' -H 'Content-Type: application/json' https://example.com/login
我得到与 amd64 arch case 相同的打印输出:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>404 - Not Found</title>
</head>
<body>
<h1>404 - Not Found</h1>
<script type="text/javascript" src="//wpc.75674.betacdn.net/0075674/www/ec_tpm_bcon.js"></script>
</body>
</html>
我使用的 gcc/g++ 和 aarch64-linux-gnu-g++/aarch64-linux-gnu-gcc 编译器都使用多架构功能构建相同版本 9.3.0 的位置。
有谁知道我可能做错了什么?
解决方案
推荐阅读
- python - ImportError:libcudart.so.8.0:无法打开共享对象文件:没有这样的文件或目录* | 我的系统中有 cuda9.0 而不是 cuda 8
- python - 在 JS 客户端将响应转换为骆驼案例,并在服务器 fastapi 上将请求数据转换为蛇案例
- r-raster - 需要 TRUE/FALSE 的 rasterFromXYZ 缺失值
- go - 最少的重新编译
- reactjs - OrderBy 和 where 查询在 firebase 中不能同时工作
- javascript - reactjs + typescript 出现错误:类型“字符串”不可分配给类型“从不”
- python - Python - 芹菜自动更新
- python - 与超类型不兼容的签名 - 用于强制命名的抽象方法与 Liskov
- firefox - 无法使用 Firefox 在本地测试 WebAssembly 页面 - 未定义 SharedArrayBuffer
- magento2 - 每个产品仅第一次触发 addToCart 事件