docker_practice/image/commit.md

132 lines
7.8 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# commit
> [](../container)
`docker commit` 使 `docker commit` 使 `Dockerfile`
`docker run` 使 Docker Hub 使
Web
```bash
$ docker run --name webserver -d -p 80:80 nginx
```
`nginx` `webserver` 80 访 `nginx`
Linux Docker使 Docker Desktop for Mac/Windows访<http://localhost>;如果使用的是 Docker Toolbox或者是在虚拟机、云服务器上安装的 Docker则需要将 `localhost` 换为虚拟机地址或者实际云服务器地址。
访 Nginx
![](_images/images-mac-example-nginx.png)
Docker 使 `docker exec`
```bash
$ docker exec -it webserver bash
root@3729b97e8226:/# echo '<h1>Hello, Docker!</h1>' > /usr/share/nginx/html/index.html
root@3729b97e8226:/# exit
exit
```
`webserver` `bash` Shell
`<h1>Hello, Docker!</h1>` `/usr/share/nginx/html/index.html`
![](_images/images-create-nginx-docker.png)
`docker diff`
```bash
$ docker diff webserver
C /root
A /root/.bash_history
C /run
C /usr
C /usr/share
C /usr/share/nginx
C /usr/share/nginx/html
C /usr/share/nginx/html/index.html
C /var
C /var/cache
C /var/cache/nginx
A /var/cache/nginx/client_temp
A /var/cache/nginx/fastcgi_temp
A /var/cache/nginx/proxy_temp
A /var/cache/nginx/scgi_temp
A /var/cache/nginx/uwsgi_temp
```
使 Docker `docker commit`
`docker commit`
```bash
docker commit [选项] <容器ID或容器名> [<仓库名>[:<标签>]]
```
```bash
$ docker commit \
--author "Tao Wang <twang2218@gmail.com>" \
--message "修改了默认网页" \
webserver \
nginx:v2
sha256:07e33465974800ce65751acc279adc6ed2dc5ed4e0838f8b86f0c87aa1795214
```
`--author` `--message` `git`
`docker image ls`
```bash
$ docker image ls nginx
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx v2 07e334659748 9 seconds ago 181.5 MB
nginx 1.11 05a60462f8ba 12 days ago 181.5 MB
nginx latest e43d811ce2f4 4 weeks ago 181.5 MB
```
`docker history` `nginx:latest`
```bash
$ docker history nginx:v2
IMAGE CREATED CREATED BY SIZE COMMENT
07e334659748 54 seconds ago nginx -g daemon off; 95 B 修改了默认网页
e43d811ce2f4 4 weeks ago /bin/sh -c #(nop) CMD ["nginx" "-g" "daemon 0 B
<missing> 4 weeks ago /bin/sh -c #(nop) EXPOSE 443/tcp 80/tcp 0 B
<missing> 4 weeks ago /bin/sh -c ln -sf /dev/stdout /var/log/nginx/ 22 B
<missing> 4 weeks ago /bin/sh -c apt-key adv --keyserver hkp://pgp. 58.46 MB
<missing> 4 weeks ago /bin/sh -c #(nop) ENV NGINX_VERSION=1.11.5-1 0 B
<missing> 4 weeks ago /bin/sh -c #(nop) MAINTAINER NGINX Docker Ma 0 B
<missing> 4 weeks ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0 B
<missing> 4 weeks ago /bin/sh -c #(nop) ADD file:23aa4f893e3288698c 123 MB
```
```bash
docker run --name web2 -d -p 81:80 nginx:v2
```
`web2` `81` Docker Desktop for Mac/Windows Linux 访 <http://localhost:81> 看到结果,其内容应该和之前修改后的 `webserver` 一样。
使 `docker commit`
## `docker commit`
使 `docker commit` 使
`docker diff webserver` `/usr/share/nginx/html/index.html`
使 `docker commit` ****使
使使 `docker commit` 西使访