博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
docker镜像制作 - Dockerfile
阅读量:3986 次
发布时间:2019-05-24

本文共 1446 字,大约阅读时间需要 4 分钟。

使用 Dockerfile 制作 docker 镜像的方式很简单,是一种工程化的方式。

一般在项目的根目录下创建 Dockerfile 文件。

选择一个基础镜像作为底层,为了使镜像尽量小,一般选择 alpine,如果不想以任何镜像为基础则选择 scratch 。

如果基础镜像在本地无法找到,会自动从远程下载。

Dockerfile 示例:

FROM alpineADD main20 /data/www/CMD cd /data/www && ./main20

构建镜像 my-main20

docker build -t my-main20 .

注意,最后的点号代表当前目录下

Sending build context to Docker daemon 24.73 MBStep 1/3 : FROM alpine ---> a24bb4013296Step 2/3 : ADD main20 /data/www/ ---> c81bb722f41dRemoving intermediate container 6cfaa16d09cbStep 3/3 : CMD /data/www/main20 ---> Running in a64ce4b5ad72 ---> 145fef371a19Removing intermediate container a64ce4b5ad72Successfully built 145fef371a19

查看镜像

docker images REPOSITORY            TAG                 IMAGE ID            CREATED             SIZEmy-main20             latest              145fef371a19        6 seconds ago       7.71 MB

运行容器

docker run --name main20 -d my-main20 docker ps CONTAINER ID    IMAGE         COMMAND              CREATED             STATUS              PORTS    NAMESd6f1a6e70581    my-main20     "/data/www/main20"   10 minutes ago      Up 1 second                  main20

容器正在运行,进入容器

docker exec -it main20 bash报错rpc error: code = 2 desc = oci runtime error: exec failed: container_linux.go:235: starting container process caused "exec: \"bash\": executable file not found in $PATH"

容器也被终止了。

这是因为 alpine linux 基础镜像的东西比较少,一般的带应用的镜像都是没问题的。

改成

docker attach d6f1a6e70581

虽然能进去,但是只能看到打印日志信息,啥也操作不了。

改成

docker exec -it main20 sh

可正常执行命令。

转载地址:http://fjaui.baihongyu.com/

你可能感兴趣的文章
Django 的Error: [Errno 10013]错误
查看>>
机器学习实战之决策树(一)
查看>>
[LeetCode By Python] 2 Add Two Number
查看>>
python 中的 if __name__=='__main__' 作用
查看>>
机器学习实战之决策树二
查看>>
[LeetCode By Python]7 Reverse Integer
查看>>
[LeetCode By Python]9. Palindrome Number
查看>>
[LeetCode By Python]13 Roman to Integer
查看>>
[leetCode By Python] 14. Longest Common Prefix
查看>>
[LeetCode By Python]107. Binary Tree Level Order Traversal II
查看>>
[LeetCode By Python]108. Convert Sorted Array to Binary Search Tree
查看>>
[leetCode By Python]111. Minimum Depth of Binary Tree
查看>>
[LeetCode By Python]112. Path Sum
查看>>
[LeetCode By Python]118. Pascal's Triangle
查看>>
[LeetCode By Python]119. Pascal's Triangle II
查看>>
[LeetCode By Python]121. Best Time to Buy and Sell Stock
查看>>
[LeetCode By Python]122. Best Time to Buy and Sell Stock II
查看>>
[LeetCode By Python]125. Valid Palindrome
查看>>
[LeetCode By Python]136. Single Number
查看>>
[LeetCode BY Python]155. Min Stack
查看>>