Files
docker-docs/content/language/cpp/containerize.md
Pradumna Saraf 1b6a6d530e docs: add language specific guide for c++ (#19903)
* docs: add language specific guide for c++

* docs: add C++ language support to the language index page

* docs: Update _index.md

* docs: update C++ guide paths

* Update content/language/c-plus-plus/containerize.md

Co-authored-by: Craig Osterhout <103533812+craig-osterhout@users.noreply.github.com>

* Update content/language/c-plus-plus/containerize.md

Co-authored-by: Craig Osterhout <103533812+craig-osterhout@users.noreply.github.com>

* Update content/language/c-plus-plus/containerize.md

Co-authored-by: Craig Osterhout <103533812+craig-osterhout@users.noreply.github.com>

* Update content/language/c-plus-plus/containerize.md

Co-authored-by: Craig Osterhout <103533812+craig-osterhout@users.noreply.github.com>

* Update content/language/c-plus-plus/containerize.md

Co-authored-by: Craig Osterhout <103533812+craig-osterhout@users.noreply.github.com>

* Update content/language/c-plus-plus/develop.md

Co-authored-by: Craig Osterhout <103533812+craig-osterhout@users.noreply.github.com>

* Update content/language/c-plus-plus/configure-ci-cd.md

Co-authored-by: Craig Osterhout <103533812+craig-osterhout@users.noreply.github.com>

* Update _index.md

* guides: use /cpp instead of /c-plus-plus

Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>

* Update content/language/cpp/develop.md

Co-authored-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>

* Update content/language/cpp/containerize.md

Co-authored-by: Craig Osterhout <103533812+craig-osterhout@users.noreply.github.com>

---------

Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
Co-authored-by: Craig Osterhout <103533812+craig-osterhout@users.noreply.github.com>
Co-authored-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
2024-06-05 09:16:36 -07:00

91 lines
2.5 KiB
Markdown

---
title: Containerize a C++ application
keywords: C++, containerize, initialize
description: Learn how to containerize a C++ application.
---
## Prerequisites
* You have a [Git client](https://git-scm.com/downloads). 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:
```console
$ 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.
```text
├── 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:
- [Dockerfile](../../reference/dockerfile.md)
- [.dockerignore](../../reference/dockerfile.md#dockerignore-file)
- [compose.yml](../../compose/compose-file/_index.md)
## Run the application
Inside the `c-plus-plus-docker` directory, run the following command in a
terminal.
```console
$ docker compose up --build
```
Open a browser and view the application at [http://localhost:8080](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 -d
```
Open a browser and view the application at [http://localhost:8080](http://localhost:8080).
In the terminal, run the following command to stop the application.
```console
$ docker compose down
```
For more information about Compose commands, see the [Compose CLI
reference](../../compose/reference/_index.md).
## Summary
In this section, you learned how you can containerize and run your C++
application using Docker.
Related information:
- [Build with Docker guide](../../build/guide/index.md)
- [Docker Compose overview](../../compose/_index.md)
## 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" >}}