惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
T
Threatpost
Latest news
Latest news
N
News | PayPal Newsroom
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Help Net Security
Help Net Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
AI
AI
Simon Willison's Weblog
Simon Willison's Weblog
TaoSecurity Blog
TaoSecurity Blog
The Last Watchdog
The Last Watchdog
L
LINUX DO - 热门话题
Google DeepMind News
Google DeepMind News
T
Threat Research - Cisco Blogs
O
OpenAI News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
The Exploit Database - CXSecurity.com
NISL@THU
NISL@THU
Application and Cybersecurity Blog
Application and Cybersecurity Blog
S
Securelist
小众软件
小众软件
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Martin Fowler
Martin Fowler
S
SegmentFault 最新的问题
Cisco Talos Blog
Cisco Talos Blog
云风的 BLOG
云风的 BLOG
AWS News Blog
AWS News Blog
GbyAI
GbyAI
N
News and Events Feed by Topic
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
美团技术团队
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
S
Schneier on Security
博客园 - 聂微东
V2EX - 技术
V2EX - 技术
T
Troy Hunt's Blog
SecWiki News
SecWiki News
S
Secure Thoughts
B
Blog RSS Feed
Hugging Face - Blog
Hugging Face - Blog
WordPress大学
WordPress大学
腾讯CDC
H
Heimdal Security Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Apple Machine Learning Research
Apple Machine Learning Research
月光博客
月光博客
www.infosecurity-magazine.com
www.infosecurity-magazine.com
P
Privacy International News Feed

博客园 - 逝者如斯(乎)

Redis和Memcached的区别详解 分布式系统原理与范型 - 电子支付系统 CSS3 (1) - Beginner Shell Script (2) - global.sh Python (1) - 7 Steps to Mastering Machine Learning With Python Java面试题(1)- 高级特性 Master Nginx(8) - Troubleshooting Techniques Master Nginx(7) - Nginx for the Developer Master Nginx(6) - The Nginx HTTP Server Hadoop实战课程 Java EE (14) -- SSH配置 Self-Paced Training (3) - Docker Operations Self-Paced Training (1) - Introduction to Docker Shell Script Tutorials (0 ~ 62) Master Nginx(5) - Reverse Proxy Advanced Topics Master Nginx(4) - Nginx as a Reverse Proxy Master Nginx(3) - Using the Mail Module Mater Nginx(2) - A Configuration Guide Master Nginx(1) - Installing Nginx and Third-Party Modules
Self-Paced Training (2) - Docker Fundamentals
逝者如斯(乎) · 2016-03-27 · via 博客园 - 逝者如斯(乎)

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

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

  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

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

  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