docker常用操作

Dabby@ybbaD


vi /etc/ssh/sshd_config


yum install net-tools -y


etc/yum.repos.d/vim docker.repo
(下载安装源)
——-
[dockerrepo]
name=Docker 
Repositorybaseurl=https://yum.dockerproject.org/repo/experimental/centos/7/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg


——-
yum install bridge_utils -y(分配网桥工具)


ip a


brctl addbr abc


ip addr add 123.0.0.1/16 dev (设置网段)


ip link set dev abc up(启动网桥)


/lib/systemd/system/docker.service


/user/bin/dokerd -b=abc


————————————————————————————————————————————————————————————-


安装docker:yum install docker-engine -y


systemctl restart docker(启动服务)
systemctl enable docker(开机启动)


docker login daocloud.io


docker pull daocloud.io/library/ubuntu:trusty-20150228.11


docker images


docker run 
exit
(退出)


docker run -ti daocloud.io/library/centos:6.8 /bin/bash
docker run -ti daocloud.io/library/ubuntu:trusty-20150228.11 /bin/bash
(cli命令,启动docker镜像)




yum install -y  nginx(rpm -qa nginx)


apt-get install nginx(dpkg -s nginx)


docker run -ti -p 82:80 nginx:1028 bash
(启动一个nginx镜像)


curl http://mirrors.aliyun.com/repo/epel.repo -o /tmp/
(下载安装源)


nginx
(启动)


netstat -ntlap


cd nginx/


vi conf.d/default.conf 


cd /usr/share/nginx/html/


vi abc.txt


docker ps -a


cd abc


vi dockerfile


docker build -t nginx2:10288 -f dockerfile .


docker run -tl -p 81:80 -v /home:/volume1/log nginx:1028 bash 


docker run -d -p 83:80 -v /home/log:/usr/share/nginx/html nginx2:10288 


docker exec -ti b0afc4f7369b bash


docker inspect daocloud.io/library/centos:6.8


docker network ls


docker network create --help


docker network connect --ip 123.0.0.100 mybridge b0afc4f7369b




docker exec -ti b0afc4f7369b bash










——————————————————————————————-
yum -y install redis


bind 127.0.0.1 192.168.1.45 修改ip端口






 redis-server redis.conf 启动进程


redis-cli -h 172.16.1.66 在redis客户端连接其他的redis


redis-cli -h 172.16.1.66  keys "history_orderInfo_*"|xargs redis-cli -h 172.16.1.66 del




统计:redis-cli keys "history_*"|wc -l


删除:redis-cli keys "history_*"|xargs redis-cli del 


















————————————————————————————————————————————————————————————————————————


————————————————————————————————————————————————————————————————————————




docker images


docker pull daocloud.io/library/ubuntu:latest


以交互的形式启动一个虚拟机镜像,可直接操作这个镜像
docker run -ti daocloud.io/library/ubuntu:latest /bin/bash


 
后台运行
docker run -d daocloud.io/library/ubuntu:latest /sbin/init


进入
docker exec -ti 7fae8f009efe bash


(7fae8f009efe:上面后台运行的容器id)






eixt
docker ps -a




在容器中安装nginx:
apt-get update


apt-get install nginx








第二个镜像:


docker pull daocloud.io/library/nginx:latest
——————-


1、dockerfile:


 wget http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz


2、新建docker源


vim dockerfile


FROM daocloud.io/library/ubuntu:latest
env timedate 2017-05-24


3、拷贝jdk包到镜像中


 FROM daocloud.io/library/ubuntu:latest
env timedate 2017-05-24
add jdk1.8.0_131 /home
env JAVA_HOME /home/jdk1.8.0_131
env PATH $PATH:$JAVA_HOME/bin:$JAVA_HOME/db/bin:$JAVA_HOME/jre/bin




(jdk1.8.0_131文件夹覆盖了镜像中的home目录,这里缓存了tar包解决问题)




4、构建dockerfile




docker build -t java8:first -f dockerfile .








5、执行镜像;


docker run -d -p 80:8080 -p 2222:22 java8:first /sbin/init


(-p 80:8080):80外网,8080ubuan端口
(-p 2222:22):2222外网,22容器22远程端口


docker ps




6、进入镜像(交互环境)




docker exec -ti 7fae8f009efe /bin/bash




7fae8f009efe(镜像id)




7、删除容器、镜像




先停止容器,然后删除容器,最后删除镜像














《《《《《《《《《《《《《《《


一条龙
1、


from daocloud.io/library/ubuntu:latest
env timedate 2017-05-24
add jdk-8u131-linux-x64.tar.gz /home/
add apache-maven-3.3.9-bin.tar.gz /home/
add apache-tomcat-8.5.15.tar.gz /home/
run apt-get update
run apt-get install nginx -y


env JAVA_HOME /home/jdk1.8.0_131
env MAVEN_HOME /home/apache-maven-3.3.9
env PATH $PATH:$JAVA_HOME/bin:$JAVA_HOME/db/bin:$JAVA_HOME/jre/bin:$MAVEN_HOME/bin




2、docker build -t java8:stable -f dockerfile .


3、docker run -d -p 81:8080 -p 222:22 java8:first /sbin/init(不适用)




docker run -d -p 81:8080 -v /share:/sharE java8:stable /sbin/init(逻辑卷映射到主机)

阅读更多
换一批

没有更多推荐了,返回首页