Docker安装应用(Centos6.5_x64)
Authoer::jom_ch@2014/7/23
Docker官网 http://www.docker.com/
一,安装EPEL
关于EPEL:https://fedoraproject.org/wiki/EPEL/zh-cn
>rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
>rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
>yum -y install yum -priorities
二,安装Docker
>yum -y install docker-io
>service docker start
>chkconfig docker on
三,应用Docker
1,获取Centos镜像
>docker pull centos:latest
2,查看镜像运行情况
>docker images centos
3,在容器下运行 shell bash
>docker run -i -t centos /bin/bash
4,停止容器
>docker stop <CONTAINER ID>
5,查看容器日志
>docker logs -f <CONTAINER ID>
6,删除所有容器
>docker rm $(docker ps -a -q)
7,删除镜像
>docker rmi <image id/name>
8,提交容器更改到镜像仓库中
>docker run -i -t centos /bin/bash
>useradd myuser
>exit
>docker ps -a |more
>docker commit <CONTAINER ID> myuser/centos
9,创建并运行容器中的 hello.sh
>docker run -i -t myuser/centos /bin/bash
>touch /home/myuser/hello.sh
>echo "echo \"Hello,World!\"" > /home/myuser/hello.sh
>chmod +x /home/myuser/hello.sh
>exit
>docker commit <CONTAINER ID> myuser/centos
>docker run -i -t myuser/centos /bin/sh /home/myuser/hello.sh
10,在容器中运行Nginx
在容器中安装好Nginx,并提交到镜像中
>docker run -t -i -p 80:80 nginx/centos /bin/bash
启动Nginx
>/data/apps/nginx/sbin/nginx
(还不清楚如何在后台运行!!!)
在浏览器访问宿主机80端口。
11,映射容器端口
>docker run -d -p 192.168.9.11:2201:22 nginx/centos /usr/sbin/sshd -D
用ssh root@192.168.9.11 -p 2201 连接容器,提示:
Connection to 192.168.1.205 closed.(此问题还未解决!!!)
可能会遇到的问题:
##在容器里面修改用户密码的时候报错:
/usr/share/cracklib/pw_dict.pwd: No such file or directory
PWOpen: No such file or directory
解决:
yum -y reinstall cracklib-dicts
(责任编辑:IT) |