8 个版本 (4 个重大更新)

0.5.0 2020 年 2 月 19 日
0.4.0 2019 年 1 月 22 日
0.3.3 2018 年 10 月 29 日
0.3.2 2018 年 9 月 28 日
0.1.0 2017 年 2 月 28 日

#345Cargo 插件

每月 29 次下载

MIT/Apache

20KB
443

Build Status Build status

cargo-pack-docker

一个 Docker 的 cargo-pack;将您的应用程序打包到 Docker 镜像中,无需 Dockerfile 进行部署

此产品处于测试阶段。请自行承担风险使用

安装

编译后的二进制文件

查看版本

构建中

cargo install cargo-pack-docker

用法

cargo pack-docker [-p package] [--release] [TAG]
# if your configurated tag in Cargo.toml is hoge:0.1.0, the TAG will be hoge
# if TAG is omitted and you have only one `[[package.metadata.pack.docker]]` section, it will be used

配置

# configuration of cargo-pack
[package.metadata.pack]
default-packers = ["docker"]
# files will be placet to /opt/app
files = ["README.md"]

# configuration of cargo-pack-docker
[[package.metadata.pack.docker]]
# tag of the created image. Can be omitted.
# Default to PACKAGE_NAME:latest for debug profile
# and PACKAGE_NAME:PACKAGE_VERSION for release profile
tag = "hoge:0.1.0"
# base image of the docker image. Required.
base-image = "ubuntu:16.04"
# the bin to include into the docker image.
# will be placed to /opt/app/bin/
# can be omitted if the project have only one binary target.
bin = "aaa"
# `ENTRYPOINT` of Dockerfile. optional.
entrypoint = ["aa", "bb"]
# `CMD` of Dockerfile. optional.
cmd = ["c", "d"]
# inject command into the Dockerfile. optional
inject = "
ENV RUST_LOG debug
RUN apt install libpq-dev
"

# you can write another configuration 
[[package.metadata.pack.docker]]
base-image = "ubuntu:16.04"
bin = "bbb"

使用第一个配置,使用以下 Dockerfile 内容构建 Docker 镜像

FROM ubuntu:16.04

RUN mkdir -p /opt/app/bin
COPY README.md /opt/app
COPY aaa /opt/app/bin
WORKDIR /opt/app

ENV RUST_LOG debug
RUN apt install libpq-dev


ENTRYPOINT ["aa", "bb"]
CMD ["c", "d"]

在 Docker 中运行 cargo-pack-docker

存在镜像

blackenedgold/cargo-pack-docker .

要使用 cargo-pack-docker Docker 镜像构建 Docker 镜像,请运行以下命令。

docker run \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v `which docker`:/usr//bin/docker \
  -v $(pwd):/tmp/app \
  -w /tmp/app
  blackenedgold/cargo-pack-docker \
  cargo pack-docker

如果您更喜欢 docker-compose,请使用此 YAML 片段。

  build:
    image: blackenedgold/cargo-pack-docker:0.4.0-rust-1.32.0
    command: cargo pack-docker
    working_dir: /tmp/app
    volumes:
      - ./ /tmp/app
      - /var/run/docker.sock:/var/run/docker.sock
      # your path to docker
      - /usr/bin/docker:/usr/bin/docker

依赖

~9–20MB
~272K SLoC