Docker镜像的构建
-
容器内部像linux一样操作,然后提交容器成镜像
-
Dokcerfile提交镜像
一
-
创建一个容器
|
1
2
3
4
|
[root@web01 ~]
#docker run --name mynginx01 -it centos
[root@web01 ~]
# docker ps -a
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 ~]
# docker commit -m "mynginx01" be750c11ab1e mynginx/mynginx:v1
sha256:5143358c3833b4ee5a40b847d86dee072dc7c0bade9358e7d83323d6349784b0
[root@web01 ~]
#
mynginx
/mynginx
:v1 仓库/镜像名称:版本标签
[root@web01 ~]
# docker images
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]
# cat 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]
# cat index.html
hello liuhx
[root@web01 dockerfile]
# pwd
/root/dockerfile
[root@web01 dockerfile]
#
|
构建镜像
|
1
2
|
cd
/root/dockerfile
Docker build -t mynginx
/mynginx03
:03 ./
|
|
1
2
3
|
[root@web01 dockerfile]
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mynginx
/mynginx03
v3 8c81f51923e5 2 minutes ago 374.6 MB
|
启动容器:
|
1
2
|
[root@web01 dockerfile]
# docker run -d --name nginx007 -p 86:80 mynginx/mynginx03:v3
6f2501177ac00e064b22c6c3045b973dc41935e82180753a21a14f3224f5f323
|
