DockerFile

用来构建Docker镜像

步骤:

  1. 编写dockerfile文件(定义一切步骤,源代码)
  2. build镜像(发布与运行的产品)
  3. run镜像 (提供服务)
  4. push镜像(dockerhub、阿里云镜像仓库等)

手工打造镜像,一段DockerFile的脚本

如centos镜像
官方很多都是基础包

FROM scratch
ADD centos-8-x86_64.tar.xz /
LABEL org.label-schema.schema-version="1.0"     org.label-schema.name="CentOS Base Image"     org.label-schema.vendor="CentOS"     org.label-schema.license="GPLv2"     org.label-schema.build-date="20210915"
CMD ["/bin/bash"]

指令

 

指令分类

 

打造自己镜像

如:

☁  home  cat DockerFile 
FROM centos 

VOLUME ["/home/volume01", "/home/volume02"]

CMD echo "----66666----"
CMD /bin/bash

build

☁  home  docker build --help 

Usage:  docker build [OPTIONS] PATH | URL | -

Build an image from a Dockerfile

Options:
      --add-host list           Add a custom host-to-IP mapping (host:ip)
      --build-arg list          Set build-time variables
      --cache-from strings      Images to consider as cache sources
      --disable-content-trust   Skip image verification (default true)
  -f, --file string             Name of the Dockerfile (Default is 'PATH/Dockerfile')
      --iidfile string          Write the image ID to the file
      --isolation string        Container isolation technology
      --label list              Set metadata for an image
      --network string          Set the networking mode for the RUN instructions during build (default "default")
      --no-cache                Do not use cache when building the image
  -o, --output stringArray      Output destination (format: type=local,dest=path)
      --platform string         Set platform if server is multi-platform capable
      --progress string         Set type of progress output (auto, plain, tty). Use plain to show container output (default "auto")
      --pull                    Always attempt to pull a newer version of the image
  -q, --quiet                   Suppress the build output and print image ID on success
      --secret stringArray      Secret file to expose to the build (only if BuildKit enabled): id=mysecret,src=/local/secret
      --squash                  Squash newly built layers into a single new layer
      --ssh stringArray         SSH agent socket or keys to expose to the build (only if BuildKit enabled) (format:
                                default|<id>[=<socket>|<key>[,<key>]])
  -t, --tag list                Name and optionally a tag in the 'name:tag' format
      --target string           Set the target build stage to build.

  ☁  home  docker build -f dockerfile01 -t donghao/centos:01 .
[+] Building 0.2s (5/5) FINISHED
=> [internal] load build definition from dockerfile01 0.0s
=> => transferring dockerfile: 130B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/centos:latest 0.0s
=> [1/1] FROM docker.io/library/centos 0.0s
=> exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:df5cd2bb5d08b60d5ce5631e976c53798d4f46399ae1936210772dba07f40f5a 0.0s
=> => naming to docker.io/donghao/centos:01 0.0s


☁ home ls
dockerfile01
☁ home docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
donghao/centos 01 df5cd2bb5d08 2 months ago 231MB

```bash

sh-4.4# cd /home
sh-4.4# ls
volume01  volume02 # 匿名挂载

[
            {
                "Type": "volume",
                "Name": "69e1d28452b108d51eee3edc01dd38e6617fd5d3922af19be167996ff1442af1",
                "Source": "/var/lib/docker/volumes/69e1d28452b108d51eee3edc01dd38e6617fd5d3922af19be167996ff1442af1/_data",
                "Destination": "/home/volume01",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            },
            {
                "Type": "volume",
                "Name": "fcf70a9f63c17821100284ba8b3cb32545241646679ca591b223f087e2501def",
                "Source": "/var/lib/docker/volumes/fcf70a9f63c17821100284ba8b3cb32545241646679ca591b223f087e2501def/_data",
                "Destination": "/home/volume02",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            }
        ]
  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值