Agenda-

Building Images

Dockerfile

Managing Images and Containers

Distributing Images on Docker Hub

Docker Volumes

Basic Container networking

Docker in continuous integration

Build New Image

  1. Create a container from an Ubuntu image and run a bash terminal: docker run -i -t ubuntu:14.04 /bin/bash
  2. Inside the container, install curl: apt-get install curl
  3. Exit the container terminal
  4. Run docker ps -a and take note of your container ID
  5. Save the container as a new image. For the repository name use <yourname>/curl. Tag the image as 1.0: docker commit <container ID> <yourname>/curl:1.0
  6. Run docker images and verify that you can see your new image

Use New Image

  1. Create a container using the new image you created in the previous exercise. Run /bin/bash as the process to get terminal access: docker run -i -t <yourname>/curl:1.0 /bin/bash
  2. Verify that curl is installed: which curl

Dockerfile Instructions

Instructions specify what to do when building the image

FROM instruction specifies what the base image should be

RUN instruction specifies a command to execute

#Example of a comment

  1. FROm ubuntu:14.04
  2.  
  3. RUN apt-get install vim
  4.  
  5. RUN apt-get install curl

Docker Build

docker build [options] [path]

Common option to tag the build: docker build -t [repository:tag] [path]

  1. docker build -t johnnytu/myimage:1.0 .
  2.  
  3. docker build -t johnnytu/myimage:1.0 myproject 

Build from Dockerfile

  1. In your home directory, create a folder called test
  2. In the test folder, create a file called “Dockerfile”
  3. In the file, specify to use Ubuntu 14.04 as the base image: FROM ubuntu:14.04
  4. Write an instruction to install curl and vim after an apt-get update: RUN apt-get update && apt-get install -y curl vim
  5. Build an image from the Dockerfile. Give it the repository <yourname>/textimage and tag it as 1.0: docker build -t johnnytu/textimage:1.0 .
  6. Create a container using your newly built image and verify that curl and vim are installed

Try CMD

  1. Go into the test folder and open your Dockerfile from the previous exercise
  2. Add the following line to the end: CMD ping 127.0.0.1 -c 30
  3. Build the image: docker build -t <yourname>/textimage:1.1 .
  4. Execute a container from the image and observe the output: docker run <yourname>/testimage:1.1
  5. Execute another container from the image and specify the echo command: docker run <yourname>/textimage:1.1 echo “hello world”
  6. Observe how the container argument overrides the CMD instruction

Push to Docker Hub

  1. Login to your Docker Hub account
  2. Create a new public repository called “testexample”
  3. Tag your local image to give it the same repo name as the repository you created on Docker Hub: docker tag <yourname>/testimage:1.1 <yourname>/testexample:1.1
  4. Push the new image to Docker Hub: docker push <yourname>/testexample:1.1
  5. Go to your Docker Hub repository and check for the tag

Mount a Volume

Volumes are mounted when creating or executing a container

Can be mapped to a host directory

Volume paths specified must be absolute

Execute a new container and mount the folder /myvolume into its file system

  1. docker run -d -P -v /myvolume nginx:1.7

Execute a new container and map the /data/src folder from the host into the /test/src folder in the container

  1. docker run -i -t -v /data/src:/test/src nginx:1.7

Create and test a Volume

  1. Execute a new container and initialise a volume at /www/website. Run a bash terminal as your container process. docker run -i -t -V /www/website ubuntu:14.04 bash
  2. Inside the container, verify that you can get to /www/website
  3. Create a file inside the /www/website folder
  4. Exit the container
  5. Commit the updated container as a new image called test and tag it as 1.0. docker commit <container ID> test:1.0
  6. Execute a new container with your test image and go into it’s bash shell. docker run -i -t test:1.0 bash
  7. Verify that the /www/website folder exists and the there are no files inside

EXPOSE net work port

Create a Link

  1. Create the source container first. docker run -d —name database postgres
  2. Create the recipient container and use the —link option. docker run -d -P —name website —link database:db nginx

Self-Paced Training (2) - Docker Fundamentals的更多相关文章

  1. Self-Paced Training (3) - Docker Operations

    AgendaTroubleshooting ContainersOverview of Security PracticesPrivate RegistryIntro to Docker Machin ...

  2. 在Docker中运行web应用

    启动一个简单的web 应用 使用社区提供的模板,启动一个简单的web应用,熟悉下各种Docker命令的使用: # docker run -d -P training/webapp python app ...

  3. 在生产环境使用Docker部署应用

    导读 Docker现在越来越流行,但是真正在生产环境部署Docker还是个比较新的概念,还没有一个标准的流程.作者是ROR的程序员,作者结合平时的部署经验,联系Docker的特点,向大家分享了其在生产 ...

  4. Docker快速入门

    Docker已经火了很长一段时间,最近打算在阿里云上好好熟悉一下Docker的相关应用,为今后的工作做准备. 基本概念 Docker是基于Go语言实现的云开源项目,诞生于2013年初,最初发起者是do ...

  5. Docker系统七:Docker数据管理

    Docker的数据管理 I. 基本概念 Docker容器一旦删除,其相关的rootf文件系统就会被删除,其容器内的数据将一并删除,为了保存相关数据,Docker提出了数据卷的概念. II. 数据卷 D ...

  6. Docker:Deploy your app

    Prerequisites Install Docker. Get Docker Compose as described in Part 3 prerequisites. Get Docker Ma ...

  7. Docker 核心技术与实现原理

    提到虚拟化技术,我们首先想到的一定是 Docker,经过四年的快速发展 Docker 已经成为了很多公司的标配,也不再是一个只能在开发阶段使用的玩具了.作为在生产环境中广泛应用的产品,Docker 有 ...

  8. Docker技术入门与实战 第二版-学习笔记-7-数据管理(volume)

    Docker 数据管理 为什么要进行数据管理呢?因为当我们在使用container时,可能会在里面创建一些数据或文件,但是当我们停掉或删除这个容器时,这些数据或文件也会同样被删除,这是我们并不想看见的 ...

  9. learning docker steps(8) ----- docker network 初次体验

    参考: docker network 主要是介绍了docker 容器之间的组网模式, 一般来说实像组网主要是依赖于bridge iptalbes vlan来实现,但是附带的如端口转发会降低效率. 新型 ...

随机推荐

  1. Spark机器学习 Day1 机器学习概述

    Spark机器学习 Day1 机器学习概述 今天主要讨论个问题:Spark机器学习的本质是什么,其内部构成到底是什么. 简单来说,机器学习是数据+算法. 数据 在Spark中做机器学习,肯定有数据来源 ...

  2. size()函数的使用

    matlab中对于矩阵的计算是十分方便的,其中关于矩阵的函数有很多 size() 在c/c++中sizeof用来求某变量所占用的字节数,在matlab中size()则可以用来求矩阵的“长度”,矩阵的长 ...

  3. MySQL创建数据库[保存mojo格式的数据库]已经常用的utf8格式数据库

    一.创建最新编码utf8mb4格式的库: CREATE DATABASE IF NOT EXISTS yourdbname CHARACTER SET utf8mb4 COLLATE utf8mb4_ ...

  4. Arcgis 10.1 求面里面所包含的点的平均值

    空间链接的作用:将面上的所有点的值加起来取平均值。赋值给面属性。(我们可以定义右击——定义合并规则 连接要素的字段映射参数中指定的合并规则仅适用于连接要素中的属性,且仅适用于多个要素与目标要素匹配   ...

  5. 使用NPIO操作Excel

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using NPOI.SS. ...

  6. K2 Blackpearl 4.6.8 安装步骤详解

    由于某些原因,我幼小的心灵受到了很大的创伤,倍感世态之炎凉,久久不能愈合,也因此很久没再接触K2 Blackpearl了.偶然来了兴趣,想整个K2的环境,闲暇之余了解其新功能,温故知新,也希望从中能讨 ...

  7. 【BZOJ 1934】 [Shoi2007]Vote 善意的投票

    Description 幼儿园里有n个小朋友打算通过投票来决定睡不睡午觉.对他们来说,这个问题并不是很重要,于是他们决定发扬谦让精神.虽然每个人都有自己的主见,但是为了照顾一下自己朋友的想法,他们也可 ...

  8. 把Ubuntu打造成Mac Macbuntu

    Macbuntu:把 Ubuntu 一键打造成完整的 Mac 风格 23八 2010 # 作者:riku/ 本文采用CC BY-NC-SA 2.5协议授权,转载请注明本文链接. Macbuntu 是一 ...

  9. 用CSS截断字符串的两种实用方法

    方法一: 复制代码 代码如下: <div style="width:300px; overflow:hidden; text-overflow:ellipsis; white-spac ...

  10. (转)关于Struts 2 拦截器参数丢失问题

    from:http://www.cnblogs.com/huzx/archive/2011/06/09/2076328.html 今天在做用户的登陆认证的时候出现的问题. 在传参数的时候,发现参数丢失 ...