1.构建示例
1.1 文件层级
1
2
3
4
5
6
7
| [root@k3s-storage test-build]# tree
.
├── Dockerfile
└── target
└── 123.txt
1 directory, 2 files
|
1.2 Dockerfile文件内容
1
2
3
4
5
6
7
| FROM siyu.com/alpine:latest
VOLUME /tmp
COPY target/123.txt /tmp
RUN apk add --no-cache python3
EXPOSE 8080
ENV NAME World
CMD ["python3", "-m", "http.server", "8080"]
|
1.3 进入Dockerfile所在路径,构建镜像。
1
| docker build -t alpine:v0.0.1 .
|
1.4 使用镜像启动容器
1
| docker run -d --name myapp -p 8080:8080 alpine:v0.0.1
|
注意:不可以用以下方式启动容器
1
| docker run -itd --name myapp -p 8080:8080 alpine:v0.0.1 sh
|
由于在Dockerfile已经使用CMD 定义了默认启动命令,如果使用sh 启动会覆盖掉默认启动方式。