1. 程式人生 > >grafana docker 安裝使用

grafana docker 安裝使用

1.配置yum源

vim /etc/yum.repos.d/docker.repo 新增 
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7 enabled=1 gpgcheck=1 gpgkey=https://yum.dockerproject.org/gpg

2.使用yum命令安裝docker

 yum install docker

3.啟動測試docker

service docker start
service docker status
Redirecting to
/bin/systemctl status docker.service ● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service;
disabled; vendor preset: disabled) Active: active (running) since Thu 2017-09-21 16:49:14 CST; 7s ago Docs: http://docs.docker.com Main PID: 57748 (dockerd-current) CGroup: /system.slice/docker.service ├─57748 /usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=docker-runc --exec-opt native.cgr...
└─57759 /usr/bin/docker-containerd-current -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --shim docker-containerd-shim --metrics-inte... Sep 21 16:49:13 yq-hadoop-184201 dockerd-current[57748]: time="2017-09-21T16:49:13.564336376+08:00" level=warning msg="Docker could not enable SELinux on... system" Sep 21 16:49:13 yq-hadoop-184201 dockerd-current[57748]: time="2017-09-21T16:49:13.718614700+08:00" level=info msg="Graph migration to content-addressabi...seconds" Sep 21 16:49:13 yq-hadoop-184201 dockerd-current[57748]: time="2017-09-21T16:49:13.719167634+08:00" level=info msg="Loading containers: start
." Sep 21 16:49:13 yq-hadoop-184201 dockerd-current[57748]: time="2017-09-21T16:49:13.786309409+08:00" level=info msg="Firewalld running: false" Sep 21 16:49:14 yq-hadoop-184201 dockerd-current[57748]: time="2017-09-21T16:49:14.053544531+08:00" level=info msg="Default bridge (docker0) is assigned ...address" Sep 21 16:49:14 yq-hadoop-184201 dockerd-current[57748]: time="2017-09-21T16:49:14.313472144+08:00" level=info msg="Loading containers: done." Sep 21 16:49:14 yq-hadoop-184201 dockerd-current[57748]: time="2017-09-21T16:49:14.313593050+08:00" level=info msg="Daemon has completed initialization" Sep 21 16:49:14 yq-hadoop-184201 dockerd-current[57748]: time="2017-09-21T16:49:14.313615684+08:00" level=info msg="Docker daemon" commit="0fdc778/1.12.6...n=1.12.6 Sep 21 16:49:14 yq-hadoop-184201 dockerd-current[57748]: time="2017-09-21T16:49:14.320056675+08:00" level=info msg="API listen on /var/run/docker.sock" Sep 21 16:49:14 yq-hadoop-184201 systemd[1]: Started Docker Application Container Engine.

docker run hello-world
測試docker 安裝是否有問題
docker version #檢視版本

4.下載並執行grafana ,埠對映3000
但是這樣啟動的容器資料會因為重啟而丟失所以官方推薦下面的方式來啟動

docker run -d --name=grafana -p 3000:3000 grafana/grafana

另一種方式
建立持久化volume

docker run -d -v /var/lib/grafana --name grafana-storage busybox:latest

從volume獲得資料啟動

docker run \
  -d \
  -p 3000:3000 \
  --name=grafana \
  --volumes-from grafana-storage \
  grafana/grafana

5.檢視映象

# docker images
REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE
docker.io/grafana/grafana   latest              e4accc9ea909        6 days ago          302.8 MB
docker.io/hello-world       latest              05a3bd381fc2        8 days ago          1.84 kB

6.啟動docker

 docker run -d -i -t e4accc9ea909 -p 3000:3000  /bin/bash

7.如果進入docker容器,比較常見的做法有

  1. 使用docker attach
# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                    NAMES
7d0a68fe4562        grafana/grafana     "/run.sh"           22 minutes ago      Up 22 minutes       0.0.0.0:3000->3000/tcp   grafana

docker attach 7d0a68fe4562
  1. 使用SSH
  2. 使用exec
    docker exec -it 7d0a68fe4562 /bin/bash
  3. 使用nsenter