C++ 如何为包含c++;源文件?
名为C++ 如何为包含c++;源文件?,c++,docker,debian,dockerfile,C++,Docker,Debian,Dockerfile,名为first.cpp的C++文件 #include<iostream> using namespace std; int main(){ cout << "Hello world..!!"; return 0; } #包括 使用名称空间std; int main(){ cout为了让cpp文件运行,需要先编译它,为此我们需要一个编译器。因为g++没有预装在debian:stretch上(我使用的就是这个),所以需要先安装它 FROM debian:
first.cpp的C++文件
#include<iostream>
using namespace std;
int main(){
cout << "Hello world..!!";
return 0;
}
#包括
使用名称空间std;
int main(){
cout为了让cpp文件运行,需要先编译它,为此我们需要一个编译器。因为g++没有预装在debian:stretch上(我使用的就是这个),所以需要先安装它
FROM debian:stretch
# Set the working directory
WORKDIR /tmp
# Install the compiler
RUN apt-get update && apt-get install g++ -y
# Copy the file containing the source code to WORKDIR/first.cpp
COPY first.cpp first.cpp
# Compile the program
RUN g++ first.cpp -o first
# Set the compiled program as the main command of the container
CMD ["./first"]
使用以下方法构建它:
docker build -f Dockerfile . -t=first-cpp
docker run -ti first-cpp
并使用以下命令运行它:
docker build -f Dockerfile . -t=first-cpp
docker run -ti first-cpp
这将依次运行容器并仅打印出:
Hello world..!!
这个,你不能“跑”一个C++源文件。但是我想运行<代码> ./Cudio>可执行文件..代码> @ dBaKiu < /Cord>请提供可执行文件的内容,我将更新我的答案。文件,我想在dockerfile的RUN
中使用。提前感谢。dockerfile确实做到了这一点,但它只是使用了默认的输出二进制文件名。我添加了-o参数来指定输出的名称。请检查它。