docker实战之容器基础

部署安装 条件:kernel 3.8以上,centos 7官方源 安装: 1.yum install docker docker-engine -y 配置yum源 cat > /etc/yum.repos.d/docker.repo << EOF [dockerrepo] name=Docker Repository baseurl=https://yum.dockerproject.org/repo/main/centos/7 enabled=1 gpgcheck=1 gpgkey=https://yum.dockerproject.org/gpg EOF

2.设置开机启动以及信息 systemctl start docker.service systemctl enable docker.service 查看进程状态 systemctl | grep docker

查看docker 信息 docker info

版本(client和server) docker version

docker0虚拟网桥 ip addr

换回默认的iptables服务 systemctl disable firewalld yum install iptables-services -y systemctl start iptables systemctl enable iptalbes

3.配置 文件:

/etc/sysconfig/docker contos 7以下

参数: OPTIONS用来控制docker daemon进程参数。 -H daemon绑定的地址,如:-H=unix:///var/run/docker.sock,-H=tcp=://0.0.0.0:2375 —registry-mirror 表示registry的镜像地址,—registry-mirror=http://4bc5abeb.m.daocloud.io —insecure-registry 表示(本地)私有registry的地址,—insecure-registry ${pivateRegistyHost}:5000 —selinux-enabled 是否开启SELinux,默认开启,—selinux-enabled=true —bip 表示网桥docker0使用CIDR网络地址,—bip=172.17.42.1 -b 表示采用已经创建好的网桥,-b=xxx

OPTIONS=-H=unix:///var/run/docker.sock -H=tcp=://0.0.0.0:2375 —registry-mirror=http://4bc5abeb.m.daocloud.io —selinux-enabled=true

下面是代理的设置: http_proxy=xxxxxx:8080 https_proxy=xxxxxxx:8080

/usr/lib/systemd/system/docker.service contos 7

ExecStart=/usr/bin/docker daemon -H fd:// -H=unix:///var/run/docker.sock -H=tcp://0.0.0.0:2375 —registry-mirror=http://4bc5abeb.m.daocloud.io —selinux-enabled=true

[Service] Environment=“HTTP_PROXY=xxxxxx:8080” Environment=“HTTPS_PROXY=xxxxxx:8080” Type=notify ExecStart=/usr/bin/docker daemo

4.日志 /var/log/message

5.基础命令 1)docker search java 安装

2)docker pull java 更新java

3)docker images 查询

4)docker run

docker run 里面的命令结束了,container就结束了。 docker run [OPTIONS] IMAGE[:TAG] [COMMAND] [ARG…] 决定容器的运行方式,前台还是后台执行。 docker run后面追加-d=true或者-d,容器会在后台运行。 docker exec 进入到容器中,或者attach重新连接容器的会话。 进行交互操作,如:shell脚本,必须使用-i -t参数同容器进行数据交互。 docker run 没有指定—name,deamon会自动生成一个随机字符串UUID。 docker有自动化的需求,可以将containerID输出到指定的pid文件,—cidfile=“”。 docker容器没有特权,不能在容器中再启动一个容器,这是因为默认情况下容器不能访问任何其他设备,但通过”privileged”容器就有了访问其他设备的权限。

run -rm

About
高洋,IT从业人员, 1989年4月10日, 邮箱:gy59821@163.com, 现就职于北京玩蟹科技有限公司.