-
容器内部像linux一样操作,然后提交容器成镜像
-
Dokcerfile提交镜像
一
-
创建一个容器
|
1
2
3
4
|
[root@web01 ~]
[root@web01 ~]
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
84bcc294325b nginx
"nginx -g 'daemon off"
3 seconds ago Up 3 seconds
|
2.此时已经进入容器
|
1
2
3
4
5
6
7
|
yum -y
install
wget
wget -O
/etc/yum
.repos.d
/epel
.repo
yum -y
install
nginx
vim
/etc/nginx
/nginx
.conf
...
daemon off;
退出
|
3,制作镜像
|
1
2
3
4
5
6
7
|
[root@web01 ~]
sha256:5143358c3833b4ee5a40b847d86dee072dc7c0bade9358e7d83323d6349784b0
[root@web01 ~]
mynginx
/mynginx
:v1 仓库/镜像名称:版本标签
[root@web01 ~]
REPOSITORY TAG IMAGE ID CREATED SIZE
mynginx
/mynginx
v1 5143358c3833 41 seconds ago 340.1 MB
|
二.Dokcerfile制作镜像
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
[root@web01 dockerfile]
FROM centos
MAINTAINER liuhaixiao
RUN yum -y
install
wget
RUN rpm -ivh http:
//mirrors
.aliyun.com
/epel/epel-release-latest-7
.noarch.rpm
RUN wget -O
/etc/yum
.repos.d
/CentOS-Base
.repo http:
//mirrors
.aliyun.com
/repo/Centos-7
.repo
RUN yum clean all && yum
install
nginx -y
RUN
echo
"daemon off;"
>>
/etc/nginx/nginx
.conf
ADD index.html
/usr/share/nginx/html/index
.html
EXPOSE 80
CMD [
"nginx"
]
[root@web01 dockerfile]
hello liuhx
[root@web01 dockerfile]
/root/dockerfile
[root@web01 dockerfile]
|
构建镜像
|
1
2
|
cd
/root/dockerfile
Docker build -t mynginx
/mynginx03
:03 ./
|
|
1
2
3
|
[root@web01 dockerfile]
REPOSITORY TAG IMAGE ID CREATED SIZE
mynginx
/mynginx03
v3 8c81f51923e5 2 minutes ago 374.6 MB
|
启动容器:
|
1
2
|
[root@web01 dockerfile]
6f2501177ac00e064b22c6c3045b973dc41935e82180753a21a14f3224f5f323
|
![1.png wKioL1huUl3Ac7_5AAALkUNcJ4g233.png-wh_50]()
本文转自 小小三郎1 51CTO博客,原文链接:http://blog.51cto.com/wsxxsl/1889520,如需转载请自行联系原作者