多看官网是没错的。 https://docs.docker.com/engine/reference/builder/#usage
. 和 * 在dockerfile 中区别
目录结构
[root@k8s-master model]# tree.├── aa│ ├── _aaa.md│ └── bb│ └── cc│ └── dd│ └── ee│ └── _ee.md├── Dockerfile├── Dockerfile_cp_.├── Dockerfile_cp_2├── graph.pbtxt├── instances_train.json├── publish.log└── task_0└── mask_rcnn_weight_best.h56 directories, 9 files
. 是当前 整个目录(包含目录本身)
[root@k8s-master model]# docker build -t docker_cp_test:cp_. -f Dockerfile_cp_. .Sending build context to Docker daemon 284MBStep 1/2 : FROM busybox:1.301.30: Pulling from library/busybox53071b97a884: Pull completeDigest: sha256:4b6ad3a68d34da29bf7c8ccb5d355ba8b4babcad1f99798204e7abb43e54ee3dStatus: Downloaded newer image for busybox:1.30---> 64f5d945efccStep 2/2 : COPY . /home/test/model/---> 3907e815300fSuccessfully built 3907e815300fSuccessfully tagged docker_cp_test:cp_.[root@k8s-master model]# docker run --rm -it docker_cp_test:cp_. ls /home/test/modelDockerfile aa publish.logDockerfile_cp_. graph.pbtxt task_0Dockerfile_cp_2 instances_train.json
COPY * 是目录下所有 (不包含目录本身)
https://docs.docker.com/engine/reference/builder/#copy
If
The directory itself is not copied, just its contents.
但是看到 有 ls /home/test/model/bb/cc/dd/ee/_ee.md,这个 还是没问题的。 A context is processed recursively.
多看官网是没错的。
[root@k8s-master model]# cat Dockerfile_cp_2FROM busybox:1.30COPY * /home/test/model/[root@k8s-master model]# docker build -t docker_cp_test:cp_2 -f Dockerfile_cp_2 .Sending build context to Docker daemon 284MBStep 1/2 : FROM busybox:1.30---> 64f5d945efccStep 2/2 : COPY * /home/test/model/---> e6910b62dab3Successfully built e6910b62dab3Successfully tagged docker_cp_test:cp_2[root@k8s-master model]# docker run --rm -it docker_cp_test:cp_2 ls /home/test/modelDockerfile _aaa.md instances_train.jsonDockerfile_cp_. bb mask_rcnn_weight_best.h5Dockerfile_cp_2 graph.pbtxt publish.log[root@k8s-master model]# docker run --rm -it docker_cp_test:cp_2 ls /home/test/model/bb/cc/dd/ee/_ee.md/home/test/model/bb/cc/dd/ee/_ee.md
dockerfile RUN 的 命令中 有 “”
To use a different shell, other than ‘/bin/sh’, use the_exec_form passing in the desired shell. For example:RUN ["/bin/bash", "-c", "echo hello"]
Note
The_exec_form is parsed as a JSON array, which means that you must use double-quotes (“) around words not single-quotes (‘).
比如 我想执行
sed -i "/format/a \ '\/transfer_learning'," test_factory.pysed -i "/format/d" test_factory.py
所以我就在 dockerfile 里写
FROM {{ base_image }}RUN ["/bin/bash", "-c", "sed -i \"/format/a \\ '\/trained_model_services',\" /opt/letrain-run-script/deploy_service/test_factory.py "]RUN ["/bin/bash", "-c", "sed -i \"/format/d\" /opt/letrain-run-script/deploy_service/test_factory.py "]COPY . {{ model_copy_dest }}ENTRYPOINT ["python", "/opt/letrain-run-script/deploy_service/deploy_service.py",\"--scenario={{ tarined_model_scenario }}",\"--deploy_path={{ tarined_model_location }}", "--port=80",\"--model_name={{ tarined_model_name }}"]ENV PATH=$PATH":/usr/local/cuda/bin"ENV LETRAIN_PATH="/opt/letrain"ENV export LETRAIN_PATH
before
from resoure import DeployServiceRunnerdef create_app():import falconimport osapi = falcon.API()scenario = os.environ.get('LETRAIN_SCENARIO', '')model_path = os.environ.get('LETRAIN_MODEL_PATH', '')model_name = os.environ.get('LETRAIN_MODEL_NAME', '')service_uuid = os.environ.get('SERVICE_UUID', '')api.add_route('/internal_api/service/{0}'.format(service_uuid),DeployServiceRunner(scenario, model_path, model_name))return api
after
from resoure import DeployServiceRunnerdef create_app():import falconimport osapi = falcon.API()scenario = os.environ.get('LETRAIN_SCENARIO', '')model_path = os.environ.get('LETRAIN_MODEL_PATH', '')model_name = os.environ.get('LETRAIN_MODEL_NAME', '')service_uuid = os.environ.get('SERVICE_UUID', '')api.add_route('/transfer_learning',DeployServiceRunner(scenario, model_path, model_name))return api
