0

I've got a very basic proof-of-concept C++ application, shown below:

#include <iostream>

int main()
{
    std::cout << "test" << std::endl;
    return 0;
}

When this is run locally, it prints test to the Console, as expected. However, when run on a Docker container, nothing is printed.

I'm using the microsoft/windowsservercore as for my container. Since this is still proof-of-concept, my Dockerfile consists of copying the exe of my C++ into the image, and then I'm manually running it interactively.

Am I missing something that prevents C++ applications from printing to the console inside of a Windows Docker image?

Dockerfile:

FROM microsoft/windowsservercore
COPY ./Resources /

Resources folder contains only the exe of the C++ application

Docker command: docker run --rm -it proofconcept:latest, where proofconcept is the name given during build

Darendal
  • 843
  • 9
  • 29
  • 3
    `using namespace std;` but still uses `std::endl`. Just forgo the `using` and use `std::` where needed. See [Why is “using namespace std” considered bad practice?](https://stackoverflow.com/q/1452721/868546) – Drise Mar 30 '18 at 20:28
  • Done. Doesn't fix the problem, but agree that it should be done – Darendal Mar 30 '18 at 20:30
  • Unfortunately, no, it doesn't fix your issue, but it will save you from many headaches later if you just make this habitual. Also is standard practice in every code shop I've worked in. – Drise Mar 30 '18 at 20:31
  • When you say interactively, what is that? I'm not familair with docker, but it sounds like a vm-lite? If I ran this from a terminal/command prompt window, it would show "test" as expected, but If I double clicked the exe, it would just do nothing. – Drise Mar 30 '18 at 20:33
  • Instead of starting the exe as part of starting the container, I'm starting the container, attaching to its console, and running the exe from its console. It's roughly equivalent to running straight from console, just inside the container instead of the host – Darendal Mar 30 '18 at 20:34
  • Ah, so no GUI environment at all, just a command prompt? – Drise Mar 30 '18 at 20:38
  • Correct, all command prompt, no GUI even if I wanted one – Darendal Mar 30 '18 at 20:38
  • 2
    How do you compile it, MSVC? Try compiling in /MT mode (static CRT). – rustyx Mar 30 '18 at 20:39
  • Can you include your Dockerfile and your "docker run" command in the question? – programmerq Mar 30 '18 at 20:42
  • added now. I was compiling with /MDd in MSVC. Tried switching to /Mt, but getting a large number of linker errors. Working on resolving now – Darendal Mar 30 '18 at 20:50
  • @rustyx So, /MT gave the same result, but due to a mistype on my part, I found out /MTd mode actually worked! Any idea why the mode change would fix things? – Darendal Mar 30 '18 at 21:04
  • 2
    Apps compiled with MSVC require the VC redistributable package, which installs the necessary DLLs. – rustyx Mar 30 '18 at 21:31
  • That explains it. If you add an answer, I'll mark as Accepted – Darendal Mar 30 '18 at 21:33

0 Answers0