Docker(1)Installation and Images Containers

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 <[email protected]>
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 <[email protected]>
---> 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/



猜你喜欢

转载自sillycat.iteye.com/blog/2223733