Sign inSign up

docogawa/dbyml

By docogawa

•Updated over 3 years ago

CLI to manage arguments when building a image using docker.

Image
0

217

docogawa/dbyml repository overview

⁠docker-build-yaml (dbyml)

License Version Python versions Code style: black Downloads

Docker-build-yaml (dbyml) is a CLI tool to build a docker image with build options loaded from yaml. Instead of running the docker build with many options, write options in config file, build your docker image with them. It helps you to manage build process more readable and flexible.

⁠Usage

⁠Prerequisite

To use dbyml, Docker Engine must be installed on host for build and run docker commands without root privileges (as non-root user) on client. Refer to Manage Docker as a non-root user⁠ or Docker rootless mode⁠ for non-root user setting.

⁠Create Dockerfile and Configuration file

To build your image from Dockerfile, you must make Dockerfile and config file where the build options to be passed to docker command are listed . For example, we will make the following Dockerfile and dbyml.yml in the same directory.

  • Dockerfile
FROM alpine:latest
ARG key1
RUN echo "$key1" > arg.txt && \
    cat arg.txt && \
    rm arg.txt

# You can write any process
  • dbyml.yml
    • This is a config file used by dbyml.
    • The image name field name is required.
    • The image tag field tag is optional. Default value is latest.
    • To set ARG key1 in the Dockerfile, Set build_args field and key name and its value in config.
---
image:
    name: myimage
    tag: v1.0
    build_args:
        key1: "This is set by dbyml."

⁠Build an image

Run dbyml to build the image from your Dockerfile.

$ dbyml

The image myimage:v1.0 will be created after successfully build.

If Dockerfile and config file are not in the same directory, you must set path to the Dockerfile with path field in the config.

---
image:
    name: myimage
    tag: v1.0
    path: path/to/Dockerfile

⁠Run using docker

To run dbyml in docker container, mount the followings paths on host to the container on build.

  • /var/run/docker.sock required to use the docker engine on host in a container.
  • ${PWD} A directory containing a Dockerfile and dbyml.yml must be mounted in container. See the example below.

Generate a configuration file dbyml.yml.

$ docker run --rm -it \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v ${PWD}:/work \
  docogawa/dbyml:latest --init -q

# Change owner if needed.
$ sudo chown ${USER}:${USER} dbyml.yml

Build a image from Dockerfile and dbyml.yml in the current directory.

# Check that Dockerfile and dbyml.yml exist.
$ ls -1 .
Dockerfile
dbyml.yml

# Build a image.
$ docker run --rm -it \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v ${PWD}:/work \
  docogawa/dbyml:latest

⁠Options

See https://github.com/git-ogawa/dbyml⁠ for more details.

Tag summary

Content type

Image

Digest

sha256:b8e3ef2c9…

Size

56.1 MB

Last updated

over 3 years ago

docker pull docogawa/dbyml