容器间的互连
- 启动一个容器
$ docker run -d nginx:latest
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2ac062d90d92 nginx:latest "nginx -g 'daemon of…" 4 seconds ago Up 3 seconds 80/tcp ecstatic_ellis
- 在启动一个容器并进入容器内, 通过
--link
连接上一个容器, 可以查看到--link
参数可以在容器内多添加一条本地反向dns解析的字符串
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3a80e6d74207 nginx "nginx -g 'daemon of…" 7 hours ago Up 7 hours 80/tcp epic_pasteur
$ docker run -it --link epic_pasteur:web01 centos:6.9
$ curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
$ grep '172.17.0.2' /etc/hosts
172.17.0.2 web01 2ac062d90d92 ecstatic_ellis
$ mount |grep '/dev/mapper/centos-root'
/dev/mapper/centos-root on /etc/resolv.conf type xfs (rw,seclabel,relatime,attr2,inode64,noquota)
/dev/mapper/centos-root on /etc/hostname type xfs (rw,seclabel,relatime,attr2,inode64,noquota)
/dev/mapper/centos-root on /etc/hosts type xfs (rw,seclabel,relatime,attr2,inode64,noquota)
- 在容器外查看容器的IP地址
$ docker inspect ecstatic_ellis |grep -w "IPAddress"|cut -d ':' -f 2 |uniq|cut -d ',' -f 1
"172.17.0.2"
$ curl 172.17.0.2
使用docker运行zabbix-server
- 启动一个空的Mysql服务器实例
$ docker run --name mysql-server -t
> -e MYSQL_DATABASE="zabbix"
> -e MYSQL_USER="zabbix"
> -e MYSQL_PASSWORD="zabbix"
> -e MYSQL_ROOT_PASSWORD="zabbix"
> -d mysql:5.7
> --character-set-server=utf8 --collation-server=utf8_bin
- 启动Zabbix server实例,并关联这个实例到已创建的MySQL服务器实例
$ docker run --name zabbix-server-mysql -t
-e DB_SERVER_HOST="mysql-server"
-e MYSQL_DATABASE="zabbix"
-e MYSQL_USER="zabbix"
-e MYSQL_PASSWORD="zabbix"
-e MYSQL_ROOT_PASSWORD="zabbix"
--link mysql-server:mysql
-p 10051:10051
-d zabbix/zabbix-server-mysql:latest
- 启动Zabbix web 接口,并将它与MySQL服务器实例和Zabbix server实例关联
$ docker run --name zabbix-web-nginx-mysql -t
-e DB_SERVER_HOST="mysql-server"
-e MYSQL_DATABASE="zabbix"
-e MYSQL_USER="zabbix"
-e MYSQL_PASSWORD="zabbix"
-e MYSQL_ROOT_PASSWORD="zabbix"
--link mysql-server:mysql
--link zabbix-server-mysql:zabbix-server
-p 8080:80
-d zabbix/zabbix-web-nginx-mysql:latest
- 查看容器的情况
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
58d3e7ec80bd zabbix/zabbix-web-nginx-mysql:latest "docker-entrypoint.sh" 3 minutes ago Up 3 minutes 443/tcp, 0.0.0.0:8080->80/tcp zabbix-web-nginx-mysql
99faf69bd73c zabbix/zabbix-server-mysql:latest "/sbin/tini -- /usr/…" 9 minutes ago Up 9 minutes 0.0.0.0:10051->10051/tcp zabbix-server-mysql
5debea7aa666 mysql:5.7 "docker-entrypoint.s…" 13 minutes ago Up 13 minutes 3306/tcp, 33060/tcp mysql-server
2ac062d90d92 nginx:latest "nginx -g 'daemon of…" About an hour ago Up About an hour 80/tcp ecstatic_ellis
- 查看镜像
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
zabbix/zabbix-web-nginx-mysql latest 9102571b2fef 3 days ago 155MB
zabbix/zabbix-server-mysql latest 6da679c2a6c6 3 days ago 65.8MB
mysql 5.7 1e4405fe1ea9 8 days ago 437MB
nginx latest 231d40e811cd 8 days ago 126MB
centos 6.9 2199b8eb8390 8 months ago 195MB
-
访问web界面
帐号密码:
Admin
zabbix
# docker 镜像加速 ```bash vim /etc/docker/daemon.json { "registry-mirrors": [ "https://1nj0zren.mirror.aliyuncs.com", "https://docker.mirrors.ustc.edu.cn", "http://f1361db2.m.daocloud.io", "https://registry.docker-cn.com" ], "exec-opts": ["native.cgroupdriver=systemd"], "log-driver": "json-file", "log-opts": {"max-size": "100m"} }
systemctl restart docker
<br>
# docker registry
<hr>
```bash
docker pull registry:2.7.1
docker run -d -p 5000:5000 -p 8999:5000 --restart=always --name registry -v /opt/registry:/var/lib/registry registry:2.7.1
- 加入配置文件 (
/lib/systemd/system/docker.service
)
vim /lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd --insecure-registry 172.16.240.110:8999
systemctl daemon-reload
systemctl start docker
systemctl enable docker
- 加入配置文件 (`/etc/docker/daemon.json `)
vim /etc/docker/daemon.json
{
"registry-mirrors": [
"https://1nj0zren.mirror.aliyuncs.com",
"https://docker.mirrors.ustc.edu.cn",
"http://f1361db2.m.daocloud.io",
"https://registry.docker-cn.com"
],
"insecure-registries" : [ "172.16.240.200:5000", "172.16.240.110:5000" ],
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {"max-size": "100m"}
}
systemctl restart docker
注意!!!!! `/lib/systemd/system/docker.service` 和 `/etc/docker/daemon.json ` 不能同时定义私有仓库, 否则会导致docker起不来
- 查看镜像目录
docker tag registry:2.7.1 172.16.240.110:8999/registry:2.7.1
docker push 172.16.240.110:8999/registry:2.7.1
docker pull nginx:1.16.1
docker tag nginx:1.16.1 172.16.240.110:8999/nginx:1.16.1
docker push 172.16.240.110:8999/nginx:1.16.1
curl -XGET http://172.16.240.110:8999/v2/_catalog
- 查看所有tags
curl -XGET http://172.16.240.110:8999/v2/nginx/tags/list