Docker(1)Installation and Images Containers

本文介绍了Docker的安装过程,包括在Mac和Ubuntu上的安装方法,并详细解释了Docker的基本概念如Image、Container和Repository等。此外还提供了创建、运行、管理和保存Docker容器的具体步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Docker(1)Installation and Images Containers

1. Installation
MAC
I just download the file and install from here https://docs.docker.com/installation/mac/.
> docker --version
Docker version 1.6.2, build 7c8fca2

UBUNTU
> sudo apt-get install -y docker.io
> docker --version
Docker version 1.5.0, build a8a31ef

Start the docker service
> sudo service docker start

Once your docker service is running.
> carl@ubuntu-pilot:~$ ps -ef | grep docker
root 1685 1 0 16:47 ? 00:00:00 /usr/bin/docker -d -H fd://

2. Introduction
docker virtualization is based on the operation system layer, the others are based on hardware layer.

virtual machines —> App A, B - Bins/Libs - Guest OS
Docker —> App B - Bins/Libs

Based on that, one single machine can run thousands of Docker container.

Basic Term
Image: image can use to create docker container, it is template. It is readonly.
Container: Docker run the applications in Containers. Container is on top of Image.
Repository:Repository contains a lot of images.
one repository —> a lot of images —> container on top of image —> application run on top of container
3. Use that on Ubuntu - Images
search the Image
> sudo docker search memcached

Pull the Image
> sudo docker pull memcached

List all the Images
> sudo docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
node 0.12 f9ba67676f8f 5 days ago 711.8 MB
node 0.12.4 f9ba67676f8f 5 days ago 711.8 MB
node latest f9ba67676f8f 5 days ago 711.8 MB

The list information includes which repository, image tag, image id and when it is created, what is the size of that images.

If we specify the tag, it will go with that tag, if not, it will go with latest.

Use Dockerfile to create a image
http://dockerpool.com/static/books/docker_practice/dockerfile/README.html

> mkdir ubuntu-ruby
> cat Dockerfile
#This is comment
FROM ubuntu:14.04
MAINTAINER Carl Luo <luohuazju@gmail.com>
RUN apt-get -qq update
RUN apt-get -qqy install ruby ruby-dev

Build the image
> sudo docker build -t="ubuntu-ruby:v1" .
Sending build context to Docker daemon 2.048 kB
Sending build context to Docker daemon
Step 0 : FROM ubuntu:14.04
---> 6d4946999d4f
Step 1 : MAINTAINER Docker GreenHand <luohuazju@gmail.com>
---> Using cache
---> 873801ee719d
Step 2 : RUN apt-get -qq update
---> Using cache
---> 4c6db71f543f
Step 3 : RUN apt-get -qqy install ruby ruby-dev
---> Using cache
---> d6f6754ff5dc
Successfully built d6f6754ff5dc

Start the image
> sudo docker run -t -i ubuntu-ruby:v1 /bin/bash

Change the tag
> sudo docker tag d6f6754ff5dc ubuntu-ruby:v2

Save and Load the Image
Save the docker image to your local file system
> sudo docker save -o /home/carl/install/ubuntu-ruby.v1.tar ubuntu-ruby:v1

Load the image from local file
> sudo docker load --input /home/carl/install/ubuntu-ruby.v1.tar

Remove the local images
> sudo docker rmi mongo:3.0

But sometimes, it will complain about remaining containers
> sudo docker rmi centos:centos7
Error response from daemon: Conflict, cannot delete 7322fbe74aa5 because the container 7adc92814fdb is using it, use -f to force
FATA[0000] Error: failed to remove one or more images

Solution:
> sudo docker rmi -f centos:centos7

4. Containers
There are 2 types of starting a container, one is to start a container based on a new image; the other is to resume a stopped container.

Pull one latest ubuntu OS
> sudo docker pull ubuntu

Start the container and run hello sillycat
> sudo docker run ubuntu:14.04 /bin/echo 'hello sillycat'

Start the bash command
> sudo docker run -t -i ubuntu:14.04 /bin/bash

Check the current running container
> sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4cef2c743fc0 ubuntu:14.04 "/bin/bash" 4 minutes ago Up 2 minutes drunk_rosalind

Check the docker log
> sudo docker logs drunk_rosalind

Command to check all the container
> sudo docker ps -a

Start the container
> sudo docker stop drunk_rosalind

-d parameter will put the container running in the back, but sometimes we need to login in the container.

Star the ubuntu container with this command
> sudo docker run -idt ubuntu

> sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e0b6b07723c8 ubuntu:14.04 "/bin/bash" 5 seconds ago Up 5 seconds angry_goldstine

> sudo docker attach angry_goldstine

export the snapshot of container to local file
> sudo docker export 7fc47beabcb9 > /home/carl/install/ubuntu.tar

import the snapshot to image
> cat ubuntu.tar | sudo docker import - test/ubuntu:v1.0
> sudo docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
test/ubuntu v1.0 213dbae711c1 27 seconds ago 188.1 MB

It can be imported from one REMOTE URL
sudo docker import http://xx.xx.xx/ubuntu.tar test/ubuntu:v1

Remote the Container
> sudo docker rm insane_yonath


References:
https://github.com/docker/docker
https://docs.docker.com/installation/mac/

http://aws.amazon.com/elasticmapreduce/

docker references
https://kitematic.com/
https://docs.docker.com/installation/mac/
https://docs.docker.com/installation/
http://segmentfault.com/a/1190000000366923
http://www.jianshu.com/p/26f15063de7d
http://www.infoq.com/cn/articles/docker-containers
http://www.infoq.com/cn/news/2014/12/shopify-docker-experience
http://cn.soulmachine.me/blog/20131026/
https://www.gitbook.com/book/yeasy/docker_practice/details
http://tech.uc.cn/?p=2726
http://dockone.io/article/126
http://dockerpool.com/static/books/docker_practice/install/centos.html

docker on raspberry
https://resin.io/blog/docker-on-raspberry-pi-in-4-simple-steps/
http://blog.xebia.com/2014/08/25/docker-on-a-raspberry-pi/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值