Appearance
Fresh
Build and run a C++ application using Docker Compose
Back
This guide explains how to containerize C++ applications using Docker.
C++
20 minutes
Containerize your app using a multi-stage build
Build and run a C++ application using Docker Compose
Containerize a C++ application
Copy as Markdown
Open MarkdownAsk Docs AIClaudeOpen in Claude
Table of contents
Prerequisites
- You have a Git client. The examples in this section use a command-line based Git client, but you can use any client.
Overview
This section walks you through containerizing and running a C++ application, using Docker Compose.
Get the sample application
We're using the same sample repository that you used in the previous sections of this guide. If you haven't already cloned the repository, clone it now:
console
$ git clone https://github.com/dockersamples/c-plus-plus-docker.gitYou should now have the following contents in your c-plus-plus-docker (root) directory.
text
├── c-plus-plus-docker/
│ ├── compose.yml
│ ├── Dockerfile
│ ├── LICENSE
│ ├── ok_api.cpp
│ └── README.mdTo learn more about the files in the repository, see the following:
Run the application
Inside the c-plus-plus-docker directory, run the following command in a terminal.
console
$ docker compose up --buildOpen a browser and view the application at http://localhost:8080. You will see a message {"Status" : "OK"} in the browser.
In the terminal, press ctrl+c to stop the application.
Run the application in the background
You can run the application detached from the terminal by adding the -d option. Inside the c-plus-plus-docker directory, run the following command in a terminal.
console
$ docker compose up --build -dOpen a browser and view the application at http://localhost:8080.
In the terminal, run the following command to stop the application.
console
$ docker compose downFor more information about Compose commands, see the Compose CLI\ reference.
Summary
In this section, you learned how you can containerize and run your C++ application using Docker.
Related information:
Next steps
In the next section, you'll learn how you can develop your application using containers.