在 linux 中安装Docker
以作笔记使用!(Ubuntu,Centos同理)
如何在Centos7上安装&使用docker :http://www.cnblogs.com/liuyansheng/p/5888303.html
在centos6,7安装 docker : http://www.cnblogs.com/rond/p/6020564.html
安装Docker维护的版本:
1.sudo apt-get install -y curl
2.curl -sSL https://get.docker.com/ | sudo sh
测试:
sudo docker run ubuntu echo 'hello world'
sudo docker run -i -t ubuntu /bin/bash
exit
每次敲docker命令都得带sudo,非常扰人,执行如下脚本:
添加用户组:
1.sudo groupadd docker
2.sudo gpasswd -a ${USER} docker
3.sudo service docker restart
以下内容为极客学院视频内容,http://www.jikexueyuan.com/course/832_2.html?ss=1
查看容器:
docker ps
docker ps -a
docker inspect ${docker_c_id}
docker run --name=container01 -i -t ubuntu /bin/bash
exit
docker inspect container01
docker start -i container01//重启容器
docker rm container01//删除停止的容器
守护式容器:
Ctrl+p,Ctrl+q //把交互式的容器转到后台
docker attach container01 //再进入
docker exec -it container01 /bin/sh //再进入
exit
docker run --name dc1 -d ubuntu /bin/sh -c "while true;do echo hello world;sleep 1;done"//启动守护式的容器
查看日志:
docker logs dc1
docker logs -t dc1
docker logs -tf dc1
docker logs -tf --tail 10 dc1
docker logs -tf --tail 0 dc1
查看容器内的进程:
docker top 容器名
在运行中的容器内启动新的进程:
docker exec -i -t dc1 /bin/bash
停止守护式容器:
docker stop 容器名
docker kill 容器名
docker run -P -i -t ubuntu /bin/bash //大写P对容器所有端口进行映射
docker run -p 80 -i -t ubuntu /bin/bash //大写p对容器指定端口进行映射
docker run -p 80 --name web -i -t ubuntu /bin/bash //大写p对容器指定端口进行映射
apt-get install -y nginx
apt-get install -y vim
mkdir -p /var/www/html
cd /var/www/html
vim index.html
whereis nginx
ls /etc/nginx
vim /etc/nginx/sites-enabled/default
nginx
ps -ef
docker port web
docker top web
curl http://127.0.0.1:映射端口
docker stop web
docker start -i web
docker exec web nginx
docker top web
上图来自:http://www.cnblogs.com/I-will-be-different/p/4353597.html
Docker Hub
https://hub.docker.com/
获取和推送镜像-拉取镜像(加速器)
https://hub.daocloud.io/ #配置 Docker 加速器
使用--registry-mirror选项
1.修改:/etc/sysconfig/docker
2.添加:DOCKER_OPTS="--registry-mirror=http://MIRROR-ADDR"#https://www.daocloud.io注册地址
service docker start
systemctl restart docker
#查找
docker search redis
docker run --name mykibana -e ELASTICSEARCH_URL=http://192.168.0.213:9200 -p 5601:5601 -d kibana
docker run --name mylogstash -it --rm logstash -e 'input { stdin { } } filter { kv { source => "message" field_split => "|" value_split => "=" } kv { source => "args" field_split => "&" value_split => "=" } } output { elasticsearch { hosts => ["192.168.0.213:9200"] } stdout { codec => rubydebug } }'
docker pull registry.cn-hangzhou.aliyuncs.com/aliyun_console/alisql-inner:5.6.32
docker run -ti -d --name alisql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -d registry.cn-hangzhou.aliyuncs.com/aliyun_console/alisql-inner:5.6.32 mysqld
docker exec -it alisql /bin/sh http://blog.csdn.net/halcyonbaby/article/details/46884605
编辑Dockerfile
FROM tomcat:8
ADD maven-demo/hello-world/target/hello-world.war /usr/local/tomcat/webapps/
CMD ["catalina.sh", "run"]
Build Image
$ docker build -t maven-demo-hello-world .
运行Docker镜像
$ docker run -d -p 8080:8080 maven-demo-hello-world
打开浏览器访问 http://127.0.0.1:8080/hello-world/ 将会看到 Hello World! 的输出,这表示我们编译的hello-world war 包已经成功使用 Docker 运行起来了。