How to use the Docker-compose build command line

Created
Modified

If you change a service’s Dockerfile or the contents of its build directory, run docker-compose build to rebuild it.

Docker-Compose build will read your docker-compose.yml or docker-compose.yaml.

This step enables you to add docker-compose commands to build images:

Version information
docker-compose build
docker-compose -f docker-compose.yml build
ERROR: 
Can't find a suitable configuration file in this directory or any
parent. Are you in the right directory?
Supported filenames: docker-compose.yml, docker-compose.yaml

Build the Redis with Docker Compose

Do not use cache when building the image.
docker-compose build --no-cache redis
Show more output
docker-compose --verbose build redis
Don't print anything to `STDOUT`.
docker-compose build redis -q
Run containers in the background
docker-compose up -d redis
compose.config.config.find: Using configuration files: ./docker-compose.yml
docker.utils.config.find_config_file: Trying paths: ['/root/.docker/config.json', '/root/.dockercfg']
docker.utils.config.find_config_file: No config file found
docker.utils.config.find_config_file: Trying paths: ['/root/.docker/config.json', '/root/.dockercfg']
docker.utils.config.find_config_file: No config file found
urllib3.connectionpool._make_request: http://localhost:None "GET /v1.25/version HTTP/1.1" 200 858
compose.cli.command.get_client: docker-compose version 1.25.0, build 0a186604
docker-py version: 4.1.0
CPython version: 3.7.4
OpenSSL version: OpenSSL 1.1.0l  10 Sep 2019
......
urllib3.connectionpool._make_request: http://localhost:None "GET /v1.25/networks/tmp_default HTTP/1.1" 404 44
compose.project.build: redis uses an image, skipping

Docker-compose build Help Commands and Options

Usage: 
  docker-compose build [options] [--build-arg key=val...] [SERVICE...]

Options:
--build-arg key=val
Set build-time variables for services.
--compress
Compress the build context using gzip.
--force-rm
Always remove intermediate containers.
-m, --memory MEM
Set memory limit for the build container.
--no-cache
Do not use cache when building the image.
--no-rm
Do not remove intermediate containers after a successful build.
--parallel
Build images in parallel.
--progress string
Set type of progress output (`auto`, `plain`, `tty`).
--pull
Always attempt to pull a newer version of the image.
-q, --quiet
Don't print anything to `STDOUT`.