CLI wrapper for docker build and run services based on docker-compose.yaml
in frontend project.
The only thing we concern is the dynamic version number.
- Docker Compose Wrapper CLI
- Prerequisites
- Features
- Installation
- Usage
- Commands
- Integration
- .release-it.yaml
- omit other configuration
- Development
- Reference
- Docker installed
- Docker compose installed - Can use
docker compose
command - Docker Service started
docker-compose.yaml
file existed in cwd
- Image version existence check
- Use semver version
- Use
name
andversion
fields ofpackage.json
default
npm i -g dockerc
Assume that there is the following Dockerfile
file:
FROM nginx:1.24.0-alpine-slim
COPY --chown=nginx:nginx ./dist /usr/share/nginx/html
COPY ./nginx.conf /etc/nginx/templates/default.conf.template
ARG VERSION="v0.0.0"
ENV VERSION=${VERSION}
And the following docker-compose.yaml
file:
version: "3"
services:
build:
build:
context: .
dockerfile: Dockerfile
args:
VERSION: ${VERSION}
image: ${IMAGE_NAME}:${VERSION}
dev:
image: nginx:1.24.0
container_name: example-dev
restart: unless-stopped
volumes:
- ./dist:/usr/share/nginx/html
- ./nginx.conf:/etc/nginx/templates/default.conf.template
ports:
- 8080:80
prod:
image: ${IMAGE_NAME}:${VERSION}
container_name: example-prod
restart: unless-stopped
ports:
- 80:80
Build docker images with build
service in docker-compose.yaml
file.
USAGE
$ dockerc build [--image <value>] [--no-export] [--version <value>]
FLAGS
--image=<value> Docker image name. Use the `name` field of the `package.json` file in CWD.
--no-export Don't export image after the docker build is successful.
--version=<value> Docker image version. Use the `version` field of the `package.json` file in CWD.
DESCRIPTION
Build docker images with `build` service in `docker-compose.yaml` file.
It will inject `IMAGE_NAME` and `VERSION` environment variables.
EXAMPLES
$ dockerc build # Use the `name` and `version` field of the `package.json` file in CWD.
$ dockerc build --image example # Specify image name
$ dockerc build --version 1.0.0 # Specify image version
See code: src/commands/build.ts
Start dev
service in docker-compose.yaml
file.
USAGE
$ dockerc dev
DESCRIPTION
Start `dev` service in `docker-compose.yaml` file.
EXAMPLES
$ dockerc dev
See code: src/commands/dev.ts
Display help for dockerc.
USAGE
$ dockerc help [COMMANDS] [-n]
ARGUMENTS
COMMANDS Command to show help for.
FLAGS
-n, --nested-commands Include all nested commands in the output.
DESCRIPTION
Display help for dockerc.
See code: @oclif/plugin-help
Start prod
service in docker-compose.yaml
file.
USAGE
$ dockerc prod [--image <value>]
FLAGS
--image=<value> Docker image name. Use the `name` field of the `package.json` file in CWD.
DESCRIPTION
Start `prod` service in `docker-compose.yaml` file.
The docker image will be selected from the existing image list
It will inject `IMAGE_NAME` and `VERSION` environment variables.
EXAMPLES
$ dockerc prod # Use the `name` field of the `package.json` file in CWD.
$ dockerc prod --image example # Specify image name
See code: src/commands/prod.ts
# .release-it.yaml
# omit other configuration
hooks:
"after:release": "dockerc build --version ${version}"
git clone https://github.com/jxsylar/dockerc
pnpm i
Also, It will run build
automatic.
npm link
It will install to $(npm prefix root -g)/bin/
folder, make sure this path is in PATH
env.
Now you can use dockerc
command in your shell:
docker
After code changed, build again:
pnpm run build
And the dockerc
command will automatic use the latest version, which means you don't need to run npm link
again.
Automatically update README.md
by running:
pnpm run doc
Note: The command must run after building.
npm unlink -g dockerc
This command can run in any path, which means you don't need to cd
the project path.