Build and Start the Project

To build and start the project using the Docker CLI, follow the step-by-step instructions below.

  1. Prepare Your Environment

    Ensure that you have Docker installed and the Docker daemon is running. Check your installation with:

    docker --version
    
  2. Clone the Repository

    If you have not already, clone the repository where the Go code is located:

    git clone https://github.com/docker/cli.git
    cd cli
    
  3. Set Up the Go Module

    The Go code is organized under the module name github.com/docker/cli/docs/generate. Avoid using the -mod=vendor flag while building.

    Ensure that you have the Go environment correctly configured:

    go env
    
  4. Build the Binary Using Makefile

    The project includes a Makefile that simplifies the build process. Use the make command to build the project:

    make binary
    

    This will compile the Go code and generate the output binary in the appropriate directory.

  5. Run Tests (Optional)

    Before starting the project, you may want to run the unit tests to ensure everything is functioning correctly. Execute:

    make test-unit
    
  6. Build Docker Image

    Once you have the binary, you can create a Docker image. This process typically involves creating a Dockerfile. Here is a simple example of what the Dockerfile might look like:

    FROM golang:1.16 AS build
    
    WORKDIR /app
    
    COPY . .
    
    RUN make binary
    
    FROM alpine:latest
    
    WORKDIR /app
    
    COPY --from=build /app/bin/cli /usr/local/bin/cli
    
    CMD ["cli"]
    
  7. Build the Docker Image

    With the Dockerfile defined, build the Docker image with the following command:

    docker build -t my-cli-image .
    
  8. Run the Docker Container

    After building the Docker image, you can start the project by running a container:

    docker run --rm my-cli-image
    
  9. Using Additional Makefile Functions

    The Makefile includes various functions that can be utilized as needed. For example, you can validate the vendor configuration with:

    make validate-vendor
    

    To clean up the build artifacts:

    make clean
    

    You can explore other functions by running:

    make help
    
  10. Completion and Bash Scripts

    If you would like to enable command line completion, you can use the following:

    make completion
    

    This will generate the necessary completion scripts for your shell.

The steps listed allow for a straightforward build and launch process, leveraging the capabilities provided in the Makefile within the project repository.

(Source: Makefile)