Docker教程
Docker —— 从入门到实践 简介 什么是 Docker 为什么要使用 Docker? 基本概念 Docker 镜像 Docker 容器 Docker 仓库 安装 Ubuntu 系列安装 Docker CentOS 系列安装 Docker Docker 镜像 获取镜像 列出本地镜像 创建镜像 存出和载入镜像 移除本地镜像 镜像的实现原理 Docker 容器 启动容器 后台(background)运行 终止容器 进入容器 导出和导入容器 删除容器 仓库 Docker Hub 私有仓库 仓库配置文件 Docker 数据管理 数据卷 数据卷容器 利用数据卷容器来备份、恢复、迁移数据卷 Docker 中的网络功能介绍 外部访问容器 容器互联 高级网络配置 快速配置指南 配置 DNS 容器访问控制 映射容器端口到宿主主机的实现 配置 docker0 网桥 自定义网桥 工具和示例 编辑网络配置文件 示例:创建一个点到点连接 实战案例 使用 Supervisor 来管理进程 创建 tomcat/weblogic 集群 多台物理主机之间的容器互联(暴露容器到真实网络中) 标准化开发测试和生产环境 安全 内核名字空间 控制组 Docker服务端的防护 内核能力机制 其它安全特性 总结 Dockerfile 基本结构 指令 创建镜像 底层实现 基本架构 名字空间 控制组 联合文件系统 容器格式 Docker 网络实现 Docker Compose 项目 简介 安装 使用 Compose 命令说明 YAML 模板文件 Docker Machine 项目 简介 安装 使用 Docker Swarm 项目 简介 安装 使用 swarm 调度策略 Swarm 过滤器 etcd 什么是 etcd 安装 使用 etcdctl Fig 快速搭建基于 Docker 的隔离开发环境 安装 Fig Fig客户端参考 fig.yml 参考 环境变量参考 使用 Django 入门 Fig 使用 Rail 入门 Fig 使用 Wordpress 入门 Fig CoreOS CoreOS介绍 Kubernetes 项目简介 快速上手 基本概念 kubectl 使用 基本架构 Mesos 项目 简介 Mesos + Marathon 安装与使用 Mesos 基本原理与架构 Mesos 配置项解析 Mesos 常见框架 附录一 Docker命令查询 附录二 常见仓库介绍 Ubuntu CentOS MySQL MongoDB Redis Nginx WordPress Node.js 附录三 资源链接

发布于 2015-09-22 15:33:55 | 495 次阅读 | 评论: 0 | 来源: 网络整理

Dockerfile 由一行行命令语句组成,并且支持以 # 开头的注释行。

一般的,Dockerfile 分为四部分:基础镜像信息、维护者信息、镜像操作指令和容器启动时执行指令。

例如

# This dockerfile uses the ubuntu image
# VERSION 2 - EDITION 1
# Author: docker_user
# Command format: Instruction [arguments / command] ..

# Base image to use, this must be set as the first line
FROM ubuntu

# Maintainer: docker_user <docker_user at email.com> (@docker_user)
MAINTAINER docker_user docker_user@email.com

# Commands to update the image
RUN echo "deb http://archive.ubuntu.com/ubuntu/ raring main universe" >> /etc/apt/sources.list
RUN apt-get update && apt-get install -y nginx
RUN echo "\ndaemon off;" >> /etc/nginx/nginx.conf

# Commands when creating a new container
CMD /usr/sbin/nginx

其中,一开始必须指明所基于的镜像名称,接下来推荐说明维护者信息。

后面则是镜像操作指令,例如 RUN 指令,RUN 指令将对镜像执行跟随的命令。每运行一条 RUN 指令,镜像添加新的一层,并提交。

最后是 CMD 指令,来指定运行容器时的操作命令。

下面是一个更复杂的例子

# Nginx
#
# VERSION               0.0.1

FROM      ubuntu
MAINTAINER Victor Vieux <victor@docker.com>

RUN apt-get update && apt-get install -y inotify-tools nginx apache2 openssh-server

# Firefox over VNC
#
# VERSION               0.3

FROM ubuntu

# Install vnc, xvfb in order to create a 'fake' display and firefox
RUN apt-get update && apt-get install -y x11vnc xvfb firefox
RUN mkdir /.vnc
# Setup a password
RUN x11vnc -storepasswd 1234 ~/.vnc/passwd
# Autostart firefox (might not be the best way, but it does the trick)
RUN bash -c 'echo "firefox" >> /.bashrc'

EXPOSE 5900
CMD    ["x11vnc", "-forever", "-usepw", "-create"]

# Multiple images example
#
# VERSION               0.1

FROM ubuntu
RUN echo foo > bar
# Will output something like ===> 907ad6c2736f

FROM ubuntu
RUN echo moo > oink
# Will output something like ===> 695d7793cbe4

# You᾿ll now have two images, 907ad6c2736f with /bar, and 695d7793cbe4 with
# /oink.
最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务