标签:
Docker这玩意流行已经有一阵子,之前一直不愿意去碰它,是觉得它还不够稳定。虽说各类软文铺天盖地,什么Paas微服务,容器引擎,轻量级虚拟机(当然底层的cgroups,lxc技术早已耳熟能详)等等,对这些往往不置可否,原因只有一个:大规模工业级场景应用还未曾出现,或者说未曾亲历。
时间来到了最近,由于工作需求,需要做一些MQ镜像,所以系统化的学习了Docker(当然,催生我系统化学习的动力不仅是要深度使用它,还有Go语言这两年本身的实践魅力)。这篇文章简单记录了Docker的一些使用心得及其感受,欢迎大家轻拍。
作为忠实的Linuxer,Ubuntu是我最钟爱的办公平台,当然自己的实践也是基于该平台的,如果是其它平台,请查看我参考文档里面的那几个在线文章。安装脚本如下:
sudo sh -c "echo deb http://get.docker.com/ubuntu docker main > /etc/apt/sources.list.d/docker.list" sudo apt-get update apt-get install lxc-docker
Client version: 1.4.1 Client API version: 1.16 Go version (client): go1.3.3 Git commit (client): 5bc2ff8 OS/Arch (client): linux/amd64 Server version: 1.4.1 Server API version: 1.16 Go version (server): go1.3.3 Git commit (server): 5bc2ff8
sudo groupadd docker # 添加当前用户到docker用户组里,这里我是以von登陆的 sudo gpasswd -a von docker sudo service docker restart docker version #若未生效,则系统重启 sudo reboot
Giving non-root access
The docker daemon always runs as the root user, and since Docker version 0.5.2, the docker daemon binds to a Unix socket instead of a TCP port. By default that Unix socket is owned by the user root, and so, by default, you can access it with sudo.
Starting in version 0.5.3, if you (or your Docker installer) create a Unix group called docker and add users to it, then the docker daemon will make the ownership of the Unix socket read/writable by the docker group when the daemon starts. The docker daemon
must always run as the root user, but if you run the docker client as a user in the docker group then you don‘t need to add sudo to all the client commands. As of 0.9.0, you can specify that a group other than docker should own the Unix socket with the -G
option.
Warning: The docker group (or the group specified with -G) is root-equivalent; see Docker Daemon Attack Surface details.
一旦安装ok,找个官方Helloworld示例玩玩,执行如下命令:
docker pull learn/tutorial docker run learn/tutorial /bin/echo hello world
############################################################ # Dockerfile to run RocketMQ Containers # Based on Ubuntu Image ############################################################ # Set the base image to use to Ubuntu FROM ubuntu # Set the file maintainer (your name - the file's author) MAINTAINER gosling "<span style="font-family: Arial, Helvetica, sans-serif;">gosling</span>@gmail.com" # Update package repository RUN echo "deb http://archive.ubuntu.com/ubuntu trusty main universe" > /etc/apt/sources.list RUN apt-get update -y # Install python tools (so you can do add-apt-repository) RUN apt-get install -y -q python-software-properties software-properties-common #Install Oracle jdk7 #RUN # echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | debconf-set-selections && # add-apt-repository ppa:webupd8team/java -y && # apt-get update -y && # apt-get install oracle-java8-installer -y && # apt-get clean && # update-alternatives --display java && # echo "JAVA_HOME=/usr/lib/jvm/java-8-oracle" >> /etc/environment RUN add-apt-repository ppa:webupd8team/java -y && apt-get update -y && echo oracle-java7-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections && apt-get -y install oracle-java7-installer && apt-get clean && update-alternatives --display java && echo "JAVA_HOME=/usr/lib/jvm/java-7-oracle" >> /etc/environment WORKDIR /data CMD ["bash"]
docker run -i -t -p 22222:33333 ubuntu /bin/bash
nc localhost 9999 < /etc/hosts
1. Docker中文指南, http://www.widuu.com/chinese_docker/installation/ubuntu.html
2. Docker从入门到实践, http://yeasy.gitbooks.io/docker_practice/
3. Dockerfile 最佳实践, https://docs.docker.com/articles/dockerfile_best-practices/
4. Ubuntu Docker安装, https://docs.docker.com/installation/ubuntulinux/#ubuntu-trusty-1404-lts-64-bit
5. Docker如何去掉sudo, https://docs.docker.com/installation/ubuntulinux/#giving-non-root-access
6. 操作系统虚拟化方案, http://en.wikipedia.org/wiki/Operating-system-level_virtualization
7. Docker源码分析, http://www.infoq.com/cn/articles/docker-source-code-analysis-part1
8. Docker技术预览, http://www.infoq.com/cn/articles/docker-core-technology-preview
标签:
原文地址:http://blog.csdn.net/fengjia10/article/details/42916749