基于dockerfile构建镜像
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了基于dockerfile构建镜像相关的知识,希望对你有一定的参考价值。
[[email protected] static_web]# docker build --help
Usage: docker build [OPTIONS] PATH | URL | -
Build an image from a Dockerfile
Options:
--build-arg list Set build-time variables (default [])
--cache-from stringSlice Images to consider as cache sources
--cgroup-parent string Optional parent cgroup for the container
--compress Compress the build context using gzip
--cpu-period int Limit the CPU CFS (Completely Fair Scheduler) period
--cpu-quota int Limit the CPU CFS (Completely Fair Scheduler) quota
-c, --cpu-shares int CPU shares (relative weight)
--cpuset-cpus string CPUs in which to allow execution (0-3, 0,1)
--cpuset-mems string MEMs in which to allow execution (0-3, 0,1)
--disable-content-trust Skip image verification (default true)
-f, --file string Name of the Dockerfile (Default is ‘PATH/Dockerfile‘)
--force-rm Always remove intermediate containers
--help Print usage
--isolation string Container isolation technology
--label list Set metadata for an image (default [])
-m, --memory string Memory limit
--memory-swap string Swap limit equal to memory plus swap: ‘-1‘ to enable unlimited swap
--network string Set the networking mode for the RUN instructions during build (default "default")
--no-cache Do not use cache when building the image
--pull Always attempt to pull a newer version of the image
-q, --quiet Suppress the build output and print image ID on success
--rm Remove intermediate containers after a successful build (default true)
--security-opt stringSlice Security options
--shm-size string Size of /dev/shm, default value is 64MB
-t, --tag list Name and optionally a tag in the ‘name:tag‘ format (default [])
--ulimit ulimit Ulimit options (default [])
-v, --volume list Set build-time bind mounts (default [])
[[email protected] static_web]# cat Dockerfile
#Version:0.0.1
FROM ubuntu:14.04.2
MAINTAINER Michael Hu "[email protected]"
RUN apt-get update && apt-get install -y nginx
RUN echo ‘Hi I am your container‘ >/usr/share/nginx/html/index.html
EXPOSE 80
[[email protected] static_web]# sudo docker build -t="michael/static_web" .
docker run -it 4590161a4b91 /bin/bash
[[email protected] ~]# sudo docker images michael/static_web
REPOSITORY TAG IMAGE ID CREATED SIZE
michael/static_web latest 4590161a4b91 35 minutes ago 232 MB
[[email protected] ~]# sudo docker history 4590161a4b91
IMAGE CREATED CREATED BY SIZE COMMENT
4590161a4b91 35 minutes ago /bin/sh -c #(nop) EXPOSE 80/tcp 0 B
d1c417228872 35 minutes ago /bin/sh -c echo ‘Hi I am your container‘ >... 23 B
889d78cfac4a 35 minutes ago /bin/sh -c apt-get update && apt-get insta... 43.9 MB
c10b3e8bd42d 37 minutes ago /bin/sh -c #(nop) MAINTAINER Michael Hu "... 0 B
44ae5d2a191e 2 years ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0 B
<missing> 2 years ago /bin/sh -c sed -i ‘s/^#\s*\(deb.*universe\... 1.9 kB
<missing> 2 years ago /bin/sh -c echo ‘#!/bin/sh‘ > /usr/sbin/po... 195 kB
<missing> 2 years ago /bin/sh -c #(nop) ADD file:0a5fd3a659be172... 188 MB
#以守护进程的方式运行容器,以前台运行的方式启动nginx
[[email protected] ~]# sudo docker run -d -p 80 --name static_web michael/static_web > nginx -g "daemon off;"
518f90f30d984e37e36519307256e932f454ead84c030a507a12ed71af379479
#docker随机给映射一个端口到宿主机,这里是1024,浏览器访问宿主机192.160.0.103:1024
![](http://i2.51cto.com/images/blog/201806/07/86d8216577a13416b00a899affe522ce.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
[[email protected] ~]# docker port 518f90f3 80
0.0.0.0:1024
[[email protected] ~]# sudo docker port static_web 80
0.0.0.0:1024
以上是关于基于dockerfile构建镜像的主要内容,如果未能解决你的问题,请参考以下文章
docker基于Dockerfile构建mysqld服务镜像