Self-Paced Training (2) - Docker Fundamentals
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
- Create a container from an Ubuntu image and run a bash terminal: docker run -i -t ubuntu:14.04 /bin/bash
- Inside the container, install curl: apt-get install curl
- Exit the container terminal
- Run docker ps -a and take note of your container ID
- 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
- Run docker images and verify that you can see your new image
Use New Image
- 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
- 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
FROm ubuntu:14.04 RUN apt-get install vim RUN apt-get install curl
Docker Build
docker build [options] [path]
Common option to tag the build: docker build -t [repository:tag] [path]
docker build -t johnnytu/myimage:1.0 . docker build -t johnnytu/myimage:1.0 myproject
Build from Dockerfile
- In your home directory, create a folder called test
- In the test folder, create a file called “Dockerfile”
- In the file, specify to use Ubuntu 14.04 as the base image: FROM ubuntu:14.04
- Write an instruction to install curl and vim after an apt-get update: RUN apt-get update && apt-get install -y curl vim
- 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 .
- Create a container using your newly built image and verify that curl and vim are installed
Try CMD
- Go into the test folder and open your Dockerfile from the previous exercise
- Add the following line to the end: CMD ping 127.0.0.1 -c 30
- Build the image: docker build -t <yourname>/textimage:1.1 .
- Execute a container from the image and observe the output: docker run <yourname>/testimage:1.1
- Execute another container from the image and specify the echo command: docker run <yourname>/textimage:1.1 echo “hello world”
- Observe how the container argument overrides the CMD instruction
Push to Docker Hub
- Login to your Docker Hub account
- Create a new public repository called “testexample”
- 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
- Push the new image to Docker Hub: docker push <yourname>/testexample:1.1
- 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
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
docker run -i -t -v /data/src:/test/src nginx:1.7
Create and test a Volume
- 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
- Inside the container, verify that you can get to /www/website
- Create a file inside the /www/website folder
- Exit the container
- Commit the updated container as a new image called test and tag it as 1.0. docker commit <container ID> test:1.0
- Execute a new container with your test image and go into it’s bash shell. docker run -i -t test:1.0 bash
- Verify that the /www/website folder exists and the there are no files inside
EXPOSE net work port
Create a Link
- Create the source container first. docker run -d —name database postgres
- 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的更多相关文章
- Self-Paced Training (3) - Docker Operations
AgendaTroubleshooting ContainersOverview of Security PracticesPrivate RegistryIntro to Docker Machin ...
- 在Docker中运行web应用
启动一个简单的web 应用 使用社区提供的模板,启动一个简单的web应用,熟悉下各种Docker命令的使用: # docker run -d -P training/webapp python app ...
- 在生产环境使用Docker部署应用
导读 Docker现在越来越流行,但是真正在生产环境部署Docker还是个比较新的概念,还没有一个标准的流程.作者是ROR的程序员,作者结合平时的部署经验,联系Docker的特点,向大家分享了其在生产 ...
- Docker快速入门
Docker已经火了很长一段时间,最近打算在阿里云上好好熟悉一下Docker的相关应用,为今后的工作做准备. 基本概念 Docker是基于Go语言实现的云开源项目,诞生于2013年初,最初发起者是do ...
- Docker系统七:Docker数据管理
Docker的数据管理 I. 基本概念 Docker容器一旦删除,其相关的rootf文件系统就会被删除,其容器内的数据将一并删除,为了保存相关数据,Docker提出了数据卷的概念. II. 数据卷 D ...
- Docker:Deploy your app
Prerequisites Install Docker. Get Docker Compose as described in Part 3 prerequisites. Get Docker Ma ...
- Docker 核心技术与实现原理
提到虚拟化技术,我们首先想到的一定是 Docker,经过四年的快速发展 Docker 已经成为了很多公司的标配,也不再是一个只能在开发阶段使用的玩具了.作为在生产环境中广泛应用的产品,Docker 有 ...
- Docker技术入门与实战 第二版-学习笔记-7-数据管理(volume)
Docker 数据管理 为什么要进行数据管理呢?因为当我们在使用container时,可能会在里面创建一些数据或文件,但是当我们停掉或删除这个容器时,这些数据或文件也会同样被删除,这是我们并不想看见的 ...
- learning docker steps(8) ----- docker network 初次体验
参考: docker network 主要是介绍了docker 容器之间的组网模式, 一般来说实像组网主要是依赖于bridge iptalbes vlan来实现,但是附带的如端口转发会降低效率. 新型 ...
随机推荐
- Oracle Lock 概述
按锁的机制分类 排他锁( X ):如果事务T对对象A加上排他锁,则只允许T对A对象读取和修改,其他事务不能对A增加任何锁,直到T释放加载A上的排他锁 共享锁( S ):如果事务T对表A加上共享锁,则事 ...
- Python urllib2多进程共享cookies
如果想多个进程共享同一个cookies,不用每个进程都重新登录,可以就cookies保存到一个文件,然后多个进程直接共享一个锁来实现 1.一个进程登录完成后,把cookies保存到一个文件里面 sel ...
- WPF中Expander控件样式,ListBox的样式(带checkbox)恢复
Expander控件样式: <ControlTemplate x:Key="ExpanderToggleButton" TargetType="ToggleButt ...
- mac 下 sphinx + mysql + php 实现全文搜索(xampp)(1)
原理: 使用sphinx 中的indexer 生成索引数据 service/web 端 利用searched 调用索引数据 步骤: 下载 sphinx: 下载地址:http://sphinxsea ...
- 数据库 mysql 优化器原理
MySQL查询优化器有几个目标,但是其中最主要的目标是尽可能地使用索引,并且使用最严格的索引来消除尽可能多的数据行. 你的最终目标是提交SELECT语句查找数据行,而不是排除数据行.优化器试图排除数据 ...
- 【css】web标准
网页主要由三部分组成:结构(Structure).表现(Presentation)和行为(Behavior) 结构重点理解: XHTML 1.应用形式 ccs+div 2000 2.基于xml 和x ...
- 【socket】TCP 和 UDP 在socket编程中的区别
一.TCP与UDP的区别 基于连接与无连接 对系统资源的要求(TCP较多,UDP少) UDP程序结构较简单 流模式与数据报模式 TCP保证数据正确性,UDP可能丢包 TCP保证数据顺序,UD ...
- ExtJs 4.2.1 报错:Uncaught TypeError: Cannot call method 'getItems' of null
做项目的时候遇到这个问题,搞了一上午终于解决了,让我们看看是什么问题: buttons: [ { text: '保存', icon: '../../../Images/extjs/disk.png', ...
- C# 5.0 TAP 模式下的HTTP Get和Post
标题有点瘆人,换了工作之后很少写代码了,之前由于签了保密协议,不敢把代码拿出来分享给大家,只能摘抄网上的, 今斗胆拿出来晒晒,跪求指点,直接上代码吧 public class HTTPHelper : ...
- 1030: [JSOI2007]文本生成器 - BZOJ
Description JSOI交给队员ZYX一个任务,编制一个称之为“文本生成器”的电脑软件:该软件的使用者是一些低幼人群,他们现在使用的是GW文本生成器v6版.该软件可以随机生成一些文章―――总是 ...