[Done] Docker Admin

[ Reference] 

菜鸟Docker教程 : http://www.runoob.com/docker/docker-tutorial.html

Official Doc: https://docs.docker.com/engine/

Docker Hub: https://hub.docker.com/

Docker Image in China: 

https://hub.tenxcloud.com/

https://c.163.com/hub#/m/home/

Docker Commands: http://www.runoob.com/docker/docker-command-manual.html

About Image and Container: http://www.wtoutiao.com/p/Xa2DNs.html

[ Install ]

To install docker: 

$ sudo apt-get update
$ sudo apt-get install curl
$ curl -k -sSl https://get.docker.com | sudo sh

* OR sudo apt-get install -y docker.io

* OR wget -qO- https://get.docker.com/ | sh 

To test if install is ok: docker run hello-world 

To install private registry

http://www.youruncloud.com/blog/13.html

http://www.cnblogs.com/lienhua34/p/4922130.html

For non-root user to use docker:

* sudo groupadd docker

sudo gpasswd -a ${USER} docker

sudo systemctl restart docker

* user logout and login again

[ Image Management ]

docker images

To list all the local images

docker search <image_name>

To look for image in Docker Hub

docker history <image_name:tag>

To show history of a docker image.

docker pull <[registry:]image_name:tag>

To download a image from a registry.

E.g. docker pull ubuntu:13.10

docker push <[registry:]image_name:tag>

To upload an image to a registry.

docker rmi <image_name>

To remove a docker image.

docker commit [-m="xxx"] [-a="xxx"] <container_id> [image_name:tag]

To crate a new image (based on a container).

-m: commit message (comments)

-a: auther string

image_name:tag : the new image name.

E.g. docker commit -m="has update" -a="runoob" e218edb10161 runoob/ubuntu:v2

docker build [-t image:tag] <dir>

To make a image by <dir>/Dockerfile.

Reference (general): http://os.51cto.com/art/201507/485007.htm

Reference (about entrypoint and cmd): http://cloud.51cto.com/art/201411/457338.htm 

Example:

########################################
# Dockerfile to build XiLe Portal container images
# Based on Ubuntu 16.04
########################################

# Set the base image to Ubuntu
FROM ubuntu:16.04

# File Author / Maintainer
MAINTAINER Eric YAO

# Add application repository URL to the default sources
ADD sources.list /etc/apt
# RUN echo "deb http://archive.ubuntu.com/ubuntu/ raring main universe" >> /etc/apt/sources.list

# Update the repository
RUN apt-get update

# Download and Install tools
RUN apt-get install -y wget vim net-tools

# Download and Install Nginx
RUN apt-get install -y nginx

# Download and Install vsftpd
RUN apt-get install -y vsftpd

# Download and Install mediainfo
RUN apt-get install -y mediainfo

# Set environment variables
# ENV TERM=linux

# Expose ports
EXPOSE 80

# Add the startup script
ADD startup.sh /

# Set the 'root' process :-)
CMD ["/startup.sh"]
Dockerfile
startup.sh
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
sources.list
To build: docker build -t xile .
To run: docker run -d -p 80:80 -p 21:21 --name xile xile

docker tag <tag_name> <image_id>

To give a new tag to a docker image.

docker save <-o filename> <image_name> 

To export an image to a tar file.

docker load  [-i filename]

To import an image from a tar file.

[ Container Control ]

docker ps [-a]

To show info about all the running containers.

-a: list all the containers (by default only show the running containers).

docker stats

To show containers' resource usage stats.

docker run [options] <image>[:tag] [cmd] [arg...]

To create a container and make it running.

Reference: http://www.open-open.com/lib/view/open1422492851548.html

-t: create a pts (pseudo termal) on the container.

-i: interactive mode (connect the stdio to the pts?).

-d: deamon mode.

-p [host_ip:]host_port:internal_port[/udp]:  Publish a container᾿s port to the host.

-P: Publish all exposed ports to the host interfaces.

--expose=[]: Expose a port or a range of ports from the container without publishing it to your host.

-h: set hostname.

-v host_dir:container_dir: map a host dir to a dir in the container.

-m: memory limit

-c=: CPU shares.

-e: set environment variables.

--restart={always|no|on-failure}

--name: to give a name to the container.

E.g. docker run -i -t ubuntu:15.10 /bin/bash

E.g. docker run -d ubuntu:15.10 /bin/sh -c "while true; do echo hello world; sleep 1; done"

docker restart <container_id | container_name>

To restart a running container.

docker exec [-i] [-t] <image> [cmd]

To connect to a container, start a new process and exec a command.

E.g. docker exec -it 87f444d49b33 /bin/bash

docker stop <container_id | container_name>

To stop a running container.

docker rm <container_id | container_name>

To remove a container.

docker attach <container_id | container_name>

To connect to a running container.

docker top <container_id | container_name>

To 'top' all the processes running in the container.

docker port <container_id | container_name>

To show port mapping info.

docker logs [-f] <container_id | container_name>

To show stdout info.

-f: output like 'tail -f'

docker diff <container_id | container_name>

To show changes on the container's file system.

docker inspect <container_id | container_name | image_id>

To output a JSON file about a docker container or image's status and config info

docker cp <container_id | container_name :/path> <host_path>

To copy a file from container to host

[ Commands - Genearl ]

docker info

To show the information about the docker.

docker version

To show docker version.

docker <command> --help

To show help information about a docker command.

[ Management - Docker UI ]

Reference: https://hub.docker.com/r/abh1nav/dockerui/

To install:

docker pull abh1nav/dockerui:latest

To run:

docker run -d -p 9000:9000 -v /var/run/docker.sock:/docker.sock --name dockerui abh1nav/dockerui:latest -e="/docker.sock"

[ Management - Shipyard ]

 

[ Monitor - cAdvisor]

To Solve: the Google JS issue.

To install: 

docker pull google/cadvisor

To run: 

sudo docker run --volume=/:/rootfs:ro --volume=/var/run:/var/run:rw --volume=/sys:/sys:ro --volume=/var/lib/docker/:/var/lib/docker:ro --publish=8080:8080 --detach=true --name=cadvisor google/cadvisor:latest

To monitor:

* http://127.0.0.1:8080

* BE PATIENT :-)

[ Monitor - cadvisor + influxdb + grafana ]

Reference: http://blog.csdn.net/lijiaze_csdn/article/details/49894793

[ Mostly Used Docker Images ]

* Registry, NGINX, Redis, Ubuntu, Logspout, MongoDB, Elasticsearch, CAdvisor, MySQL, Postgrep 

[ Docker Swarm ]

[ Docker Registry ]

 

posted @ 2016-09-08 18:23  Eric.YAO  阅读(213)  评论(0)    收藏  举报