How to Start Container using ‘docker-compose build’ Command in Microsoft Windows

Posted on

Introduction

This article is showing how to start a container using a docker compose command in Microsoft Windows. in this context, the command is available from the Docker application. Furthermore, since it is in the Windows operating system, it is using a Docker Desktop application. In order to be able to have it, just install it in the Windows operating system. Actually, the installer page is available in this link. Specifically, as an example one of the installer version which is for 64-bit Windows operating system, it is available in this link. In this context, it is using an image from a public docker repository. For an example, the image is ‘httpd’ image which is an image of Apache Webserver.

How to Start Container using ‘docker-compose build’ Command in Microsoft Windows

So, what is exactly the step in order to start container using Docker Compose command ?. Below, it is the steps for doing that :

  1. First of all, just check the Docker Desktop whether it is running or not. For an example, the simple way is just by executing the Docker Desktop. Another way, just check in the task bar whether it is already running in the background process.

  2. Next, this step will use a command line in order to start the container. Just run a Command Prompt as an User Interface for executing the command.

  3. Following after, before starting the container, make sure that there is already a container exist. Furthermore, that container is actually exist after listing it before as exist below :

    C:\repository\docker\docker-image-apache-build-with-docker-compose>docker container list --all
    CONTAINER ID   IMAGE              COMMAND                  CREATED         STATUS                      PORTS     NAMES
    71bd9ac02bfb   httpd:latest       "httpd-foreground"       2 minutes ago   Exited (0) 2 seconds ago              docker-image-apache-build-with-docker-compose-apache-1
    7fdabbfd9129   mysql              "python3"                14 hours ago    Exited (0) 28 minutes ago             docker-image-build-with-docker-compose-db-1
    1eb59b0fef62   wordpress:latest   "docker-entrypoint.s…"   28 hours ago    Exited (0) 25 hours ago               wordpress-wordpress-1
    937d1783e8f7   mysql:5.7          "docker-entrypoint.s…"   28 hours ago    Exited (0) 25 hours ago               wordpress-db-1
    
    C:\repository\docker\docker-image-apache-build-with-docker-compose>
    
  4. According to the above output command execution, there are several containers available. In order to start a container using docker-compose, just use the service name. In this case, it is the service name exist in the ‘docker-compose.yml’ file. So, before going on further, the following is the content of the ‘docker-compose.yml’ file :

    version: '3.9'
    services:
      apache:
        image: httpd:latest
        ports:
        - '8080:80'
        volumes:
        - ./website:/var/www/html
    
  5. After that, just start the local Docker container. In this case, the local Docker container is not the one appear in the above output command execution. Instead, it is the name available in the ‘docker-compose.yml’. Actually, it exist in the name of ‘apache’ which is the name of the services. The following is the execution of the command to start the local Docker container :

    C:\repository\docker\docker-image-apache-build-with-docker-compose>docker-compose start apache
    [+] Running 1/1
     - Container docker-image-apache-build-with-docker-compose-apache-1  Started                                                                                           0.4s
    
    C:\repository\docker\docker-image-apache-build-with-docker-compose>
    
  6. Check the container list once more, in order to check the status of the local Docker container :

    C:\repository\docker\docker-image-apache-build-with-docker-compose>docker container list --all
    CONTAINER ID   IMAGE              COMMAND                  CREATED        STATUS                    PORTS                  NAMES
    71bd9ac02bfb   httpd:latest       "httpd-foreground"       7 hours ago    Up 32 minutes             0.0.0.0:8080->80/tcp   docker-image-apache-build-with-docker-compose-apache-1
    7fdabbfd9129   mysql              "python3"                21 hours ago   Exited (0) 7 hours ago                           docker-image-build-with-docker-compose-db-1
    1eb59b0fef62   wordpress:latest   "docker-entrypoint.s…"   35 hours ago   Exited (0) 32 hours ago                          wordpress-wordpress-1
    937d1783e8f7   mysql:5.7          "docker-entrypoint.s…"   35 hours ago   Exited (0) 32 hours ago                          wordpress-db-1
    
    C:\repository\docker\docker-image-apache-build-with-docker-compose>
  7. Finally, access port 8080 to check the Apache Webserver’s services where the service with the name of ‘apache’ in the Docker container provides. Fortunately, it is a success and it provides the following page :

    How to Start Container using 'docker-compose build' Command in Microsoft Windows
    How to Start Container using ‘docker-compose build’ Command in Microsoft Windows

Leave a Reply