Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

How to Run Docker+Compose via CMD on Windows

Docker and Docker Compose are essential tools for containerization, allowing developers to package applications and their dependencies into containers. This ensures consistency across different environments, from development to production. Docker Compose simplifies the process by enabling the definition and management of multi-container Docker applications. Running Docker and Docker Compose on Windows is crucial for developers who use Windows as their primary development environment. This article will guide you through the steps to install and run Docker and Docker Compose via CMD on a Windows machine.


Examples:


1. Installing Docker Desktop on Windows:



  • Visit the Docker Desktop download page: https://www.docker.com/products/docker-desktop

  • Download the Docker Desktop for Windows installer.

  • Run the installer and follow the on-screen instructions.

  • Once installed, Docker Desktop should start automatically. If not, you can start it manually from the Start menu.


2. Verifying Docker Installation:



  • Open Command Prompt (CMD) or PowerShell.

  • Run the following command to verify Docker is installed correctly:
     docker --version

  • You should see output similar to:
     Docker version 20.10.7, build f0df350


3. Installing Docker Compose:



  • Docker Compose is included with Docker Desktop for Windows, so you don't need to install it separately.

  • Verify the installation by running:
     docker-compose --version

  • The output should be similar to:
     docker-compose version 1.29.2, build 5becea4c


4. Creating a Docker Compose File:



  • Create a directory for your project:
     mkdir my-docker-project
    cd my-docker-project

  • Create a docker-compose.yml file with the following content:
     version: '3'
    services:
    web:
    image: nginx:latest
    ports:
    - "8080:80"


5. Running Docker Compose:



  • Navigate to the directory containing your docker-compose.yml file:
     cd my-docker-project

  • Run Docker Compose to start the services defined in the docker-compose.yml file:
     docker-compose up

  • You should see output indicating that the Nginx container is being pulled and started.

  • Open a web browser and navigate to http://localhost:8080 to see the Nginx welcome page.


6. Stopping Docker Compose:



  • To stop the running services, press Ctrl+C in the CMD window where Docker Compose is running.

  • Alternatively, you can run:
     docker-compose down


To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.