文章目录
- 创建Dockerfile
- Dockerfile的通用格式:
- 第一个Dockerfile
- 第二个Dockerfile
- Dockerfile常用命令
创建Dockerfile
Dockerfile的通用格式:
FROM alpine:latest
MAINTAINER laoliu
CMD echo 'hello docker'
第一个Dockerfile
这是第一个Dockerfile的内容:
FROM alpine:latest
MAINTAINER laoliu
CMD echo 'hello docker'
第一个Dockerfile的创建,验证, 测试运行流程:
[root@laoliu home]
[root@laoliu home]
[root@laoliu docker1]
[root@laoliu docker1]
Sending build context to Docker daemon 2.048 kB
Step 1/3 : FROM alpine:latest
Trying to pull repository docker.io/library/alpine ...
latest: Pulling from docker.io/library/alpine
bdf0201b3a05: Pull complete
Digest: sha256:28ef97b8686a0b5399129e9b763d5b7e5ff03576aa5580d6f4182a49c5fe1913
Status: Downloaded newer image for docker.io/alpine:latest
---> cdf98d1859c1
Step 2/3 : MAINTAINER loaliu
---> Running in 2f4c8881f105
---> e586be09dba6
Removing intermediate container 2f4c8881f105
Step 3/3 : CMD echo "hello Docker"
---> Running in d6209286134c
---> 388e1bb2a5f7
Removing intermediate container d6209286134c
Successfully built 388e1bb2a5f7
[root@laoliu docker1]
REPOSITORY TAG IMAGE ID CREATED SIZE
hello_docker v1 388e1bb2a5f7 2 minutes ago 5.53 MB
docker.io/nginx latest 27a188018e18 2 weeks ago 109 MB
docker.io/alpine latest cdf98d1859c1 3 weeks ago 5.53 MB
[root@laoliu docker1]
hello Docker
[root@laoliu docker1]
第二个Dockerfile
内容如下: # 为注释
FROM ubuntu
MAINTAINER laoliu
RUN sed -i 's/archive.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
RUN apt-get update
RUN apt-get install -y nginx
COPY index.html /var/www/html
ENTRYPOINT ["/usr/sbin/nginx", "-g", "daemon off;"]
EXPOSE 80
流程如下:
[root@laoliu home]
[root@laoliu home]
[root@laoliu docker2]
[root@laoliu docker2]
[root@laoliu docker2]
Sending build context to Docker daemon 4.096 kB
Step 1/8 : FROM ubuntu
---> d131e0fa2585
Step 2/8 : MAINTAINER laoliu
---> Using cache
---> 4793b2149e3f
Successfully built edd93f6989c8
[root@laoliu docker2]
a898c76111c0921b194865b44c07813cac43a286c3d5ad07f02bd32807a97c72
[root@laoliu docker2]
<html>
<h1>求工作...</html>
</html>
[root@laoliu docker2]
验证方法:
- 打开浏览器:
服务器地址:80
检查是否可以打开自己的网页
Dockerfile常用命令
命令 | 用途 | 样例 |
---|
FROM | base image | FROM jupyter/base-notebook |
RUN | 执行命令 | RUN apt-get update -y && apt-get upgrade -y && apt-get install -y tzdata |
ADD | 添加文件 比copy更强大, 可以将远程的文件添加到image中 | |
COPY | 拷贝文件, 可以copy文件或目录 | COPY --chown=“${UID}:${GID} ” requirements.txt . |
CMD | 执行命令, 一般用来做容器入口 | |
EXPOSE | 暴露端口 | EXPOSE 8000 |
WORKDIR | 指定路径 | WORKDIR /home/${NB_USER} |
MAINTAINER | 维护者 | |
ENV | 设定环境变量 | |
ENTRYPOINT | 容器入口, 当与CMD同时使用时, CMD 后面的命令将作为entrypoint的参数 | ENTRYPOINT [“start_server.sh”] |
USER | 指定用户 | USER root |
VOLUME | mount point 指定容器所挂载的卷 | |
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)