docker_practice/image/commit.md

132 lines
7.9 KiB
Go
Raw Normal View History

2017-12-20 23:44:09 +08:00
> [](../container)
## commit
2017-11-27 14:29:13 +08:00
`docker commit` 使 `docker commit` 使 `Dockerfile`
`docker run` 使 Docker Hub 使
Web
```bash
2017-11-13 18:19:35 +08:00
$ 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`
2019-03-08 12:21:07 +08:00
使 `docker commit` ****使 `docker diff` 线
2017-11-22 20:28:10 +08:00
使使 `docker commit` 西使访