您的位置:首页 > 运维架构 > Docker

我的Docker学习笔记

2015-09-13 21:05 621 查看
Docker学习资料:官方:http://docs.docker.com/userguide/中文:http://yeasy.gitbooks.io/docker_practice/content/introduction/what.html一、Ubuntu下安装docker安装教程:http://docs.docker.com/installation/#installation系统安装好后vi /etc/environment追加下面两行export http_proxy="http://172.17.18.84:8080"export https_proxy="https://172.17.18.84:8080"保存sudo apt-get install docker.io(等待执行完成,装完后网络会因冲突中断)sudo service docker.io stopip link del docker0 (网络恢复)vim /etc/default/docker.io追加下面两行DOCKER_OPTS="--bip=10.0.42.1/20"export http_proxy="http://172.17.18.84:8080"保存sudo service docker.io start————————————————————————————————————————————————————安装nsenterdocker run --rm -v /usr/local/bin:/target jpetazzo/nsenter验证安装是否成功which nsenterwhich docker-enter—————————————————————————————————————————————————————二、Docker基本操作例如:
sudo docker run ...
$ sudo docker stop insane_babbageCommands:attach Attach to a running containerbuild Build an image from a Dockerfilecommit Create a new image from a container's changescp Copy files/folders from the containers filesystem to the host pathdiff Inspect changes on a container's filesystemevents Get real time events from the serverexport Stream the contents of a container as a tar archivehistory Show the history of an imageimages List imagesimport Create a new filesystem image from the contents of a tarballinfo Display system-wide informationinspect Return low-level information on a containerkill Kill a running containerload Load an image from a tar archivelogin Register or Login to the docker registry serverlogs Fetch the logs of a containerport Lookup the public-facing port which is NAT-ed to PRIVATE_PORTpause Pause all processes within a containerps List containerspull Pull an image or a repository from the docker registry serverpush Push an image or a repository to the docker registry serverrestart Restart a running containerrm Remove one or more containersrmi Remove one or more imagesrun Run a command in a new containersave Save an image to a tar archivesearch Search for an image in the docker indexstart Start a stopped containerstop Stop a running containertag Tag an image into a repositorytop Lookup the running processes of a containerunpause Unpause a paused containerversion Show the docker version informationwait Block until a container stops, then print its exit code1、保持bash运行容器
$ sudo docker run -t -i ubuntu:14.04 /bin/bash

The
-t
flag
assigns a pseudo-tty or terminal inside our new container and the
-i
flag
allows us to make an interactive connection by grabbing the standard in (
STDIN
)
of the container.退出:
root@af8bae53bdd3:/# exit
2、以守护进程运行

A Daemonized Hello world

$ sudo docker run -d ubuntu:14.04 /bin/sh -c "while true; do echo hello world; sleep 1; done"

$ sudo docker ps

CONTAINER ID  IMAGE         COMMAND               CREATED        STATUS       PORTS NAMES

1e5535038e28  ubuntu:14.04  /bin/sh -c 'while tr  2 minutes ago  Up 1 minute        insane_babbage
$ sudo docker ps -l
查看输出
$ sudo docker
logs insane_babbage


停止容器$ sudo docker stop insane_babbage查看指令的帮助:例如:$ sudo docker attach --help命令详细说明和例子:
http://docs.docker.com/reference/commandline/cli/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: