Please note, this is a STATIC archive of website www.javatpoint.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
Javatpoint Logo
Javatpoint Logo

Docker Compose

It is a tool which is used to create and start Docker application by using a single command. We can use it to file to configure our application's services.

It is a great tool for development, testing, and staging environments.

It provides the following commands for managing the whole lifecycle of our application.

  • Start, stop and rebuild services
  • View the status of running services
  • Stream the log output of running services
  • Run a one-off command on a service

To implement compose, it consists the following steps.

  1. Put Application environment variables inside the Dockerfile to access publicly.
  2. Provide services name in the docker-compose.yml file so they can be run together in an isolated environment.
  3. run docker-compose up and Compose will start and run your entire app.

A typical docker-compose.yml file has the following format and arguments.

// docker-compose.yml


Installing Docker Compose

Following are the instructions to install Docker Compose in Linux Ubuntu.

Docker Compose 1

Docker-compose version

Docker Compose 2

It says, permission denied. So, make file executable.

Docker Compose 3

Now, check version again.

Docker Compose 4

Running Application using Docker Compose

Example

Follow the following example

1) Create a Directory

2) Create a file app.py.

// app.py

3) Create a file requirements.txt.

// requirements.txt

4) Create a Dockerfile.

// Dockerfile

5) Create a Compose File.

// docker-compose.yml

6) Build and Run Docker App with Compose

After running the above command, it shows the following output.

Docker Compose 5 Docker Compose 6

Now, we can see the output by following the running http url.

Output:

Docker Compose 7

Each time, when we refresh the page. It shows counter incremented by 1.

Docker Compose 8





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA