Prepare a simple docker-compose.yaml file
In this step, we will prepare a simple docker-compose.yaml
file. This file will define a basic service that we can use to demonstrate the dry-run
functionality of Docker Compose.
First, we need to install Docker Compose. Since it's not pre-installed in this environment, we will download the binary and make it executable.
sudo curl -L "https://github.com/docker/compose/releases/download/v2.20.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
This command downloads the Docker Compose binary for your system's architecture and saves it to /usr/local/bin/docker-compose
. The chmod +x
command makes the file executable.
Now, let's verify that Docker Compose is installed correctly by checking its version.
docker-compose version
You should see output indicating the installed version of Docker Compose.
Next, we will create a directory for our project and navigate into it.
mkdir ~/project/my-compose-app
cd ~/project/my-compose-app
We are now in the ~/project/my-compose-app
directory, where we will create our docker-compose.yaml
file.
Now, let's create the docker-compose.yaml
file using the nano
editor.
nano docker-compose.yaml
Inside the nano
editor, paste the following content:
version: "3.8"
services:
web:
image: nginx:latest
ports:
- "80:80"
This docker-compose.yaml
file defines a single service named web
. This service uses the nginx:latest
Docker image and maps port 80 on the host to port 80 in the container.
Save the file by pressing Ctrl + O
, then press Enter
, and exit the editor by pressing Ctrl + X
.
We have now successfully created a simple docker-compose.yaml
file.