操作系统镜像 ubuntu, debian, centos, alpine
镜像拉取
1
|
docker pull nginx:alpine
|
运行容器
1
2
3
4
5
|
root@master1:~# docker run --name liuliancao-nginx-alpine -d nginx:alpine
2037c29cbaf0cee76922b46b24133c807dcea5250d670f019e5d39bae2e6c082
root@master1:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2037c29cbaf0 nginx:alpine "/docker-entrypoint.…" 10 seconds ago Up 10 seconds 80/tcp liuliancao-nginx-alpine
|
容器执行命令
docker exec -it 容器名字 COMMAND
1
2
3
4
5
6
7
8
|
root@master1:~# docker exec -it liuliancao-nginx-alpine "ls"
bin media srv
dev mnt sys
docker-entrypoint.d opt tmp
docker-entrypoint.sh proc usr
etc root var
home run
lib sbin
|
进入容器
docker exec -it 名字 /bin/sh
1
2
|
root@master1:~# docker exec -it liuliancao-nginx-alpine /bin/sh
/ #
|
docker attach
编写docker file
官方文档build
1
2
3
4
5
6
|
root@master1:~/test# cat Dockerfile
# syntax=docker/dockerfile:1
FROM debian
COPY sources.list /etc/apt/
RUN apt-get update && apt-get install nginx -y
CMD ["/usr/sbin/nginx","-g","daemon off;"]
|
构建本地镜像
1
2
3
|
docker help build
Usage: docker build [OPTIONS] PATH | URL | -
docker build . -t my-nginx:v1 -f Dockerfile
|
从本地镜像创建并测试
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
建议刚开始不要加-d参数,并且注意-d不要放后面
root@master1:~/test# docker run --name liuliancao-nginx-custom -p 8081:80 -d my-nginx:v1
e0259d158af2e7a919f6b0456f5b3eb37d1f423f2946da63cc84398b52e2ff8e
root@master1:~/test# curl localhost:8081
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
|
导出导入镜像
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
docker help save
docker root@master1:~/flask#
docker help save
Usage: docker save [OPTIONS] IMAGE [IMAGE...]
Save one or more images to a tar archive (streamed to STDOUT by default)
Options:
-o, --output string Write to a file, instead of STDOUT
docker save -o xxx.tar repository:tag
docker help load
root@master1:~/flask# docker help load
Usage: docker load [OPTIONS]
Load an image from a tar archive or STDIN
Options:
-i, --input string Read from tar archive file, instead of STDIN
-q, --quiet Suppress the load output
docker load -i xxx.tar
|
查看镜像变更历史
1
2
3
4
5
6
7
8
|
root@master1:~/flask# docker history my-nginx:v1
IMAGE CREATED CREATED BY SIZE COMMENT
21e7e9a304bd 16 minutes ago /bin/sh -c #(nop) CMD ["/usr/sbin/nginx" "-… 0B
f82ab96e75f8 16 minutes ago /bin/sh -c #(nop) EXPOSE 80 0B
ab9665e39fe9 15 hours ago /bin/sh -c apt-get update && apt-get install… 105MB
ac3c017c13b7 15 hours ago /bin/sh -c #(nop) COPY file:6e964609d9d66af9… 412B
6f4986d78878 11 months ago /bin/sh -c #(nop) CMD ["bash"] 0B
<missing> 11 months ago /bin/sh -c #(nop) ADD file:c03517c5ddbed4053… 124MB
|