#运行hello-world docker run hello-world ##报错 docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.31/containers/create: dial unix /var/run/docker.sock: connect: permission denied. ##解决:su 以root方式运行
#docker run hello-world ##提示:没有image,然后自动下载 Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world b04784fba78d: Pull complete Digest: sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74f Status: Downloaded newer image for hello-world:latest
Hello from Docker! This message shows that your installation appears to be working correctly.
#已经启动成功
Docker 使用
1 2 3 4 5 6 7 8 9
#启动某个指定的镜像,运行hello-world root@hisen-pc:/home/hisen# docker run ubuntu:15.10 /bin/echo "Hello world" Unable to find image 'ubuntu:15.10' locally 15.10: Pulling from library/ubuntu 7dcf5a444392: Downloading 6.29MB/51.07MB 759aa75f3cee: Download complete 3fa871dc8a2b: Download complete 224c42ae46e7: Download complete
root@hisen-pc:/home/hisen# docker run -d ubuntu:15.10 /bin/sh -c "while true; do echo hello world; sleep 1; done" 8c2a843273608eb155279ce4e4f9f4c5442c2af3524ba50ca2d6c8ccbd207081
后台启动完成,会返回一串容器的ID
1 2 3 4
##查看是否有容器启动 root@hisen-pc:/home/hisen# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8c2a84327360 ubuntu:15.10 "/bin/sh -c 'while..." About a minute ago Up About a minute
CONTAINER ID:容器ID(这里是:==8c2a84327360==)
NAMES:自动分配的容器名称
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
## 查看上面那个ID的容器的log root@hisen-pc:/home/hisen# docker logs 8c2a84327360 ## 输出内容 hello world hello world
Display a live stream of container(s) resource usage statistics
Options: -a, --all Show all containers (default shows just running) --format string Pretty-print images using a Go template --help Print usage --no-stream Disable streaming stats and only pull the first result
## 查看运行的docker root@hisen-pc:/home/hisen# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b03903d6abf3 training/webapp "python app.py" 9 minutes ago Up 9 minutes 0.0.0.0:32768->5000/tcp nifty_mirzakhani
root@hisen-pc:/home/hisen# docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest 1815c82652c0 2 months ago 1.84kB woailuoli993/jblse 0.2.0 82099e8d7049 6 months ago 7.58MB ubuntu 15.10 9b9cb95443b5 13 months ago 137MB training/webapp latest 6fae60ef3446 2 years ago 349MB