content/guides/cpp/containerize.md
This section walks you through containerizing and running a C++ application, using Docker Compose.
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:
$ git clone https://github.com/dockersamples/c-plus-plus-docker.git
You should now have the following contents in your c-plus-plus-docker (root)
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:
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.
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.
In this section, you learned how you can containerize and run your C++ application using Docker.
Related information:
In the next section, you'll learn how you can develop your application using containers.