标签:
洒家近日玩了一阵子docker,写点笔记备查。
本文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] |
docker hub 几个镜像:
https://hub.docker.com/r/nickistre/ubuntu-lamp/~/dockerfile/ |
|
php |
|
mysql |
sudo docker pull ubuntu
user@ubuntu:~$ sudo docker images
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
e9d是 镜像id或镜像名
user@ubuntu:~$ sudo docker run -it -p 8080:80 e9d apache2
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
user@ubuntu:~$ sudo docker run -it -p 8080:80 e9d /bin/bash
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
user@ubuntu:~$ sudo docker ps -a
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
user@ubuntu:~$ sudo docker port ac4c
80/tcp -> 0.0.0.0:8080
sudo docker build -t mylamp/test /home/user/Docker/mylamp_test/
上例中,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)
标签:
原文地址:http://www.cnblogs.com/go2bed/p/5703117.html