The build guide that I once wrote now duplicates a lot of content with the concept guide launched a few months back. It doesn't make sense to cover the same topics multiple times, so I'm removing the older build guide and incorporating some of the topics into the build manual instead. Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
2.4 KiB
title, keywords, description
| title | keywords | description |
|---|---|---|
| Containerize a C++ application | C++, containerize, initialize | Learn how to containerize a C++ application. |
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.
Get the sample application
Clone the sample application to use with this guide. Open a terminal, change directory to a directory that you want to work in, and run the following command to clone the repository:
$ git clone https://github.com/dockersamples/c-plus-plus-docker.git
You should now have the following contents in your c-plus-plus-docker
directory.
├── c-plus-plus-docker/
│ ├── compose.yml
│ ├── Dockerfile
│ ├── LICENSE
│ ├── ok_api.cpp
│ └── README.md
To 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.
$ docker compose up --build
Open 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.
$ docker compose up --build -d
Open a browser and view the application at http://localhost:8080.
In the terminal, run the following command to stop the application.
$ docker compose down
For 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.
{{< button text="Develop your application" url="develop.md" >}}