Docker 常用命令
2016-07-25 13:09
483 查看
洒家近日玩了一阵子docker,写点笔记备查。
本文URL: http://www.cnblogs.com/go2bed/p/5703117.html
官方文档: https://docs.docker.com/
如:
user@ubuntu:~$ sudo docker search debian
docker hub 几个镜像:
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu latest 4ef6a5ece191 3 days ago 120.1 MB
reinblau/lamp latest e9df29833f32 9 days ago 703.8 MB
[b]user@ubuntu:~$ sudo docker run -it -p 8080:80 e9d apache2[/b]
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.1. Set the 'ServerName' directive globally to suppress this message
[b]user@ubuntu:~$ sudo docker run -it -p 8080:80 e9d /bin/bash[/b]
root@ac4c74c9ac8a:/var/www/html# apache2
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
在后台运行,启动后容器内自动运行 /root/run.sh
sudo docker run -itd -p 8080:80 e9d /root/run.sh
-d, --detach=false Run container in background and print container ID
-i, --interactive=false Keep STDIN open even if not attached
-P, --publish-all=false Publish all exposed ports to random ports
-p, --publish=[] Publish a container's port(s) to the host
-t, --tty=false Allocate a pseudo-TTY 分配一个伪TTY?
sudo docker attach ac4c
退出,一定不要用ctrl+c,那样就是让docker容器停止了。
要用如下快捷键:先按,ctrl+p;再按,ctrl+q
-q, --quiet=false Only display numeric IDs
[b]user@ubuntu:~$ sudo docker port ac4c[/b]
80/tcp -> 0.0.0.0:8080
上例中,dockerfile存在于 /home/shen/Docker/mylamp_test/,镜像tag为mylamp/test
后面跟上标签或ID,跟标签会先删除标签(untag),如果没有标签指向镜像,就删除(delete)镜像。
跟ID,删除所有相关标签(untag),再删除(delete)镜像。
sudo docker rmi 2318
sudo docker rmi ubuntu
sudo docker stop $(sudo docker ps -q)
删除(已经停止的,正在运行的不能删除)容器
sudo docker rm $(sudo docker ps -a -q)
本文URL: http://www.cnblogs.com/go2bed/p/5703117.html
官方文档: https://docs.docker.com/
搜索镜像
镜像可以去 https://hub.docker.com/ 搜索,或者使用命令如:
user@ubuntu:~$ sudo docker search debian
NAME | DESCRIPTION | STARS | OFFICIAL | AUTOMATED |
debian | Debian is a Linux distribution that's comp... | 1519 | [OK] | |
neurodebian | NeuroDebian provides neuroscience research... | 25 | [OK] | |
jesselang/debian-vagrant | Stock Debian Images made Vagrant-friendly ... | 8 | [OK] | |
armbuild/debian | ARMHF port of debian | 8 | [OK] |
nickistre/ubuntu-lamp | https://hub.docker.com/r/nickistre/ubuntu-lamp/~/dockerfile/ |
php | https://hub.docker.com/_/php/ |
mysql | https://hub.docker.com/_/mysql/ |
下载镜像
sudo docker pull ubuntu显示本地镜像
user@ubuntu:~$ sudo docker imagesREPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu latest 4ef6a5ece191 3 days ago 120.1 MB
reinblau/lamp latest e9df29833f32 9 days ago 703.8 MB
运行镜像,映射端口
开启lamp镜像,映射主机8080端口到容器80端口
e9d是 镜像id或镜像名[b]user@ubuntu:~$ sudo docker run -it -p 8080:80 e9d apache2[/b]
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.1. Set the 'ServerName' directive globally to suppress this message
[b]user@ubuntu:~$ sudo docker run -it -p 8080:80 e9d /bin/bash[/b]
root@ac4c74c9ac8a:/var/www/html# apache2
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
在后台运行,启动后容器内自动运行 /root/run.sh
sudo docker run -itd -p 8080:80 e9d /root/run.sh
参数:
加上 -i -t 可以 ctrl+p ctrl+q 退出。-d, --detach=false Run container in background and print container ID
-i, --interactive=false Keep STDIN open even if not attached
-P, --publish-all=false Publish all exposed ports to random ports
-p, --publish=[] Publish a container's port(s) to the host
-t, --tty=false Allocate a pseudo-TTY 分配一个伪TTY?
依附到运行中的容器
ac4c 是容器号sudo docker attach ac4c
退出,一定不要用ctrl+c,那样就是让docker容器停止了。
要用如下快捷键:先按,ctrl+p;再按,ctrl+q
列出容器
[b]user@ubuntu:~$ sudo docker ps -a[/b]CONTAINER ID | IMAGE | COMMAND | CREATED | STATUS | PORTS | NAMES |
ac4c74c9ac8a | e9d:latest | "/bin/bash" | 7 minutes ago | Up 7 minutes | 0.0.0.0:8080->80/tcp | insane_mayer |
3a4b37b41ea7 | e9d:latest | "apache2" | 7 minutes ago | Exited (0) 7 minutes ago | suspicious_darwin |
参数
-a, --all=false Show all containers (default shows just running)-q, --quiet=false Only display numeric IDs
查看端口映射
ac4c是容器id[b]user@ubuntu:~$ sudo docker port ac4c[/b]
80/tcp -> 0.0.0.0:8080
从dockerfile 创建镜像
sudo docker build -t mylamp/test /home/[b]user/Docker/mylamp_test/[/b]上例中,dockerfile存在于 /home/shen/Docker/mylamp_test/,镜像tag为mylamp/test
参数
-t, --tag= Repository name (and optionally a tag) for the image删除镜像
先删除所有依赖容器,再删除镜像。后面跟上标签或ID,跟标签会先删除标签(untag),如果没有标签指向镜像,就删除(delete)镜像。
跟ID,删除所有相关标签(untag),再删除(delete)镜像。
sudo docker rmi 2318
sudo docker rmi ubuntu
删除容器
sudo docker rm e81批量操作容器
停止正在运行的容器sudo docker stop $(sudo docker ps -q)
删除(已经停止的,正在运行的不能删除)容器
sudo docker rm $(sudo docker ps -a -q)
相关文章推荐
- Docker1.12 + Swarm 构建动态微服务应用
- 在Docker容器中进行Flask应用的开发
- docker命令大全
- mysql 5.7 docker 主从复制架构搭建教程
- 使用Docker开发你的PHP应用
- mysql 5.7 docker 主从复制架构搭建教程
- docker daemon log
- centos7 docker安装
- kubernetes+docker监控之Docker监控——cadvisor
- 基于Spring Boot和Spring Cloud实现微服务架构学习(六)-Docker应用
- 基于Spring Boot和Spring Cloud实现微服务架构学习(五)-Docker总结
- Dockerfile-centos:tengine
- DICOM:Docker实现增量发布之前期准备
- ubuntu安装(owncloud-docker安装)
- mysql 5.7 docker 主从复制架构搭建
- DOCKER
- docker学习笔记-批量删除停止运行的容器
- 卸载docker
- Docker镜像文件存储结构
- Docker的“谎言”