docker 学习手册
安装
透過Docker 套件庫安裝最新版本
要安裝最新的 Docker 版本,首先需要安裝 apt-transport-https 支援,之後透過新增套件庫來安裝。
$ sudo apt-get install apt-transport-https
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
$ sudo bash -c "echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list"
$ sudo apt-get update
$ sudo apt-get install -y lxc-docker
### 快速安裝法(建議使用)
$ curl -sSL https://get.docker.com/ | sudo sh
备份与恢复
docker 备份img 恢复img
┌─[✗]─[yunpiao@parrot]─[~/Project/Blog]
└──╼ $sudo docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
10.108.115.90:5040/benchmark_secores 1.1 64980445abc7 5 months ago 1.486 GB
10.108.115.90:5040/remnux-metasploit 2.2 ef09bbc5f2e5 6 months ago 1.767 GB
> docker save ef09bbc5f2e5> remnux.tar
> docker save -o ./a.tar ef09bbc5f2e5
> docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
celery_worker latest 4c11f755f992 2 weeks ago 1.313 GB
***/benchmark_secores 1.1 64980445abc7 5 months ago 1.486 GB
***/remnux-metasploit 2.2 ef09bbc5f2e5 6 months ago 1.767 GB
docker 备份容器 恢复容器
> sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
33c7ca6f8f18 ***/benchmark_secores:1.1 "./run.sh" 4 hours ago Up 59 minutes 0.0.0.0:5030->5030/tcp, 22/tcp desperate_brahmagupta
01881694502b ***/remnux-metasploit:2.2 "/usr/local/bin/init." 4 hours ago Up 59 minutes 0.0.0.0:55552->55552/tcp amazing_liskov
> sudo docker export 01881694502b >./mate.tar
> cat /home/export.tar | sudo docker import - busybox-1-export:latest
docker 网络相关
docker 镜像加速
网易加速
sudo echo "DOCKER_OPTS="$DOCKER_OPTS --registry-mirror=http://hub-mirror.c.163.com"" >> /etc/default/docker
service docker restart
docker 代理设置
在启动时设置好代理更方便
> https_proxy=https://<ip>:<port> docker -d
修改配置文件
sudo echo "DOCKER_OPTS="$DOCKER_OPTS --registry-mirror=http://hub-mirror.c.163.com"" >> /etc/default/docker
eg.
http_proxy=http://10.108.115.167:1080 docker -d --insecure-registry 10.0.1.44:5000 --registry-mirror=http://hub-mirror.c.163.com\
docker 镜像操作
docker 镜像 搜索
docker search ubuntu
docker search <ip>:<port>/ubuntu
docker img 改名
修改镜像名 + TAG
docker tag 原镜像名 自义定名:自定义TAG名 //实际上是新建了镜像
docker tag IMAGE_ID 自义定名:自定义TAG名 //实际上是新建了镜像
注:如果镜像已经有了名称和tag,那么这条命令就会新建一个相同IMAGE ID的镜像;
注:模板导入的镜像没有tag,所以使用docker tag添加名称和tag,参考模板导入,不会新建镜像;
docker 坑
1. 时间同步问题
-v /etc/localtime:/etc/localtime:ro
附之前博文
1 安装
sudo apt-get install apt-transport-https ca-certificates
sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net
:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
sudo cat <<EOF > /etc/apt/sources.list.d/docker.list
deb https://apt.dockerproject.org/repo ubuntu-trusty main
EOF
sudo apt-get update
sudo apt-get install -y linux-image-extra-$(uname -r)
sudo apt-get install apparmor
sudo apt-get install -y docker-engine
\`\`\` plain
#### 2、镜像
```bash
sudo docker pull ubuntu:12.04
sudo docker run -t -i ubuntu:12.04 /bin/bash
sudo docker images
sudo docker run -t -i training/sinatra /bin/bash
sudo docker commit -m "Added json gem" -a "Docker Newbee"
sudo docker save -o ubuntu_14.04.tar ubuntu:14.04
sudo docker load --input ubuntu_14.04.tar
sudo docker rmi training/sinatra
\`\`\` plain
#### 3、容器
```bash
sudo docker run ubuntu:14.04 /bin/echo 'Hello world'
sudo docker run -t -i -p80:80 --name test ubuntu:14.04 /bin/bash top
## -t 分配伪终端
## -i 标准输入保持打开
## -d 后台运行
sudo docker run -idt ubuntu:14.04
sudo docker ps
sudo docker attach <name>
sudo docker export <id > >ubnutu.tar
sudo docker import - test/ubnutu:v1.1
sudo docker rm test/ubunut
sudo docker ps -a
sudo docker rm $(docker ps -a -q )
\`\`\` plain