使用方式

  1. $ gf docker -h
  2. USAGE
  3. gf docker [MAIN] [OPTION]
  4. ARGUMENT
  5. MAIN main golang file path for "gf build", it's "main.go" in default
  6. OPTION
  7. -f, --file file path of the Dockerfile. it's "manifest/docker/Dockerfile" in default
  8. -s, --shell path of the shell file which is executed before docker build
  9. -t, --tag tag name for this docker, which is usually used for docker push
  10. -p, --push auto push the docker image to docker registry if "-t" option passed
  11. -e, --extra extra build options passed to "docker image"
  12. -h, --help more information about this command
  13. EXAMPLE
  14. gf docker
  15. gf docker -t hub.docker.com/john/image:tag
  16. gf docker -p -t hub.docker.com/john/image:tag
  17. gf docker main.go
  18. gf docker main.go -t hub.docker.com/john/image:tag
  19. gf docker main.go -t hub.docker.com/john/image:tag
  20. gf docker main.go -p -t hub.docker.com/john/image:tag
  21. DESCRIPTION
  22. The "docker" command builds the GF project to a docker images.
  23. It runs "gf build" firstly to compile the project to binary file.
  24. It then runs "docker build" command automatically to generate the docker image.
  25. You should have docker installed, and there must be a Dockerfile in the root of the project.

自动编译并生成docker镜像。非必需FILE参数为编译文件路径,默认为main.go。非必需参数OPTIONSdocker build命令相同参数及选项。

使用示例

  1. $ gf docker main.go -p -t loads/gf-demos:test
  2. 2020-12-31 00:47:28.207 start building...
  3. 2020-12-31 00:47:28.207 go build -o ./bin/linux_amd64/main main.go
  4. 2020-12-31 00:47:35.894 done!
  5. Sending build context to Docker daemon 37.63MB
  6. Step 1/10 : FROM loads/alpine:3.8
  7. ---> f9fb622e6db2
  8. Step 2/10 : LABEL maintainer="john@goframe.org"
  9. ---> Using cache
  10. ---> da238418d031
  11. Step 3/10 : ENV WORKDIR /var/www/gf-demos
  12. ---> Using cache
  13. ---> 3e7129c087c9
  14. Step 4/10 : ADD ./bin/linux_amd64/main $WORKDIR/main
  15. ---> 3661a9dea494
  16. Step 5/10 : RUN chmod +x $WORKDIR/main
  17. ---> Running in 1d49d5d91080
  18. Removing intermediate container 1d49d5d91080
  19. ---> a03ee04e3380
  20. Step 6/10 : ADD public $WORKDIR/public
  21. ---> 63dd06d0e1a3
  22. Step 7/10 : ADD config $WORKDIR/config
  23. ---> fa7a57eba577
  24. Step 8/10 : ADD template $WORKDIR/template
  25. ---> 7075609b0447
  26. Step 9/10 : WORKDIR $WORKDIR
  27. ---> Running in a34ef38e1031
  28. Removing intermediate container a34ef38e1031
  29. ---> 580077998eaf
  30. Step 10/10 : CMD ./main
  31. ---> Running in ed286b518ad9
  32. Removing intermediate container ed286b518ad9
  33. ---> fbbc05842901
  34. Successfully built fbbc05842901
  35. Successfully tagged loads/gf-demos:test
  36. The push refers to repository [docker.io/loads/gf-demos]
  37. b4025b95a79f: Preparing
  38. 9e0369a57507: Preparing
  39. 46c68dcc8e12: Preparing
  40. 59adbc083ee5: Preparing
  41. 10e0b999ba57: Preparing
  42. 8e850d7b086e: Waiting
  43. d5e057db20a2: Waiting
  44. 92e898fd7f84: Waiting
  45. d9ff549177a9: Waiting
  46. ...