How to install Docker and Docker compose on your computer the quick way

Docker and Docker Compose are two powerful tools that can help you build, package, and run your applications. Docker provides a way to run applications in containers, while Docker Compose is a tool that makes it easier to manage multiple containers and define the relationships between them.

Which ever your desired use case is, in this article, we’ll go through the steps to install Docker and Docker compose the quick way.

Install Docker

Before you can install Docker Compose, you need to install Docker. If you already have Docker installed, you can skip this step. Else, Here’s how you can install Docker on the most common operating systems:

$ sudo apt update
$ sudo apt install docker.io

Install Docker Compose

Now that you have Docker installed, it’s time to install Docker Compose. Docker Compose is a separate tool that is installed on top of Docker. Here’s how you can install Docker Compose on the most common operating systems:

  • Windows and macOS: Docker Compose is included with Docker Desktop, so there’s no need to install it separately.
  • Ubuntu: Open the terminal and run the following commands:
$ sudo curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose

Verify your Installation

Once you have installed Docker and Docker Compose, you can verify the installations by running the following commands available on all operating systems.

$ docker --version
$ docker-compose --version

You should see the installed version numbers for both Docker and Docker Compose.

Write a sample Docker Compose File

Docker Compose uses a file called docker-compose.yml to define the relationships between the containers in your application. However, its not mandatory to use the exact file name, you can create your own custom file as long as it has the .yml extension.

Here’s a simple example of a Docker Compose file that runs a single container with the NGINX web server:

version: '3'
services:
  web:
    image: nginx
    ports:
      - 80:80

Start Containers with Docker Compose

Now that you have a Docker Compose file ready, you can start your containers with the docker-compose up command if you used the default naming style. If you chose the custom route, then you have to define your file as follows docker-compose -f <filename> up.

For example, if your Docker Compose file is named docker-compose.yml, you can start the containers with the following command:

$ docker-compose up

This will start the containers defined in your Docker Compose file, then print the logs to the terminal. To put the logs to the background, add -d after the up declaration.

Now, if your firewall allows you can access the NGINX web server by visiting http://localhost or http://127.0.0.1 in your web browser.

Stop and Remove Containers

When you’re done using the containers, you can stop and remove them with the docker-compose down command as below.

$ docker-compose down

This will stop and remove the containers and networks created by Docker Compose.

In conclusion, Docker and Docker Compose are powerful tools that can help you build, package, and run your applications the easy way. If you found this article useful, please share it, else, please leave a comment below.

Exit mobile version