1

docker-compose The command is too long and tired.

We can use make to help us save lives. After all, four letters are easier to remember than a bunch of letters.

The four most commonly used functions are encapsulated with make :

  • build build image
  • up (background) running service
  • down stop and delete the container (why use stop instead of down? stop just stops the container, down has a function to delete the container after stopping)
  • logs View incremental log

Makefile file can be written like this:

 NAME = ponponon/ideaboom
VERSION = 1.0.1

.PHONY: build up down logs

build:  docker-build
up: docker-compose-up
down: docker-compose-down
logs: docker-compose-logs

docker-build:
    docker build -t "${NAME}" .

docker-compose-up:
    docker-compose up -d

docker-compose-down:
    docker-compose down

docker-compose-logs:
    docker-compose logs --tail=100 -f
  • NAME = ponponon/ideaboom is the name of the image you want to package. You can use / , it is legal
  • VERSION whatever, no point
  • .PHONY Reference: makefile .PHONY usage
  • build is used to build the image, you can directly make build after git pull, without the need for docker build -t ponponon/ideaboom such a long series of commands.
  • up is to restart the containers.
  • logs The most important thing, you can view the standard output, just use it to view the log. --tail=100 -f means, first look at the 100 line at the end, and then continue to output. Equivalent to the combination of tail command -n and -f . If you don't want to read it, just ctrl+c exit
make and docker have nothing to do with each other, here Makefile is just used to simplify the command

universe_king
3.4k 声望678 粉丝