mirror of
https://github.com/wsargent/docker-cheat-sheet.git
synced 2025-12-16 23:20:13 +01:00
Moved Load/Save and Import/Export to Image section
This commit is contained in:
parent
5d8aa92f85
commit
e73160e118
1 changed files with 29 additions and 36 deletions
65
README.md
65
README.md
|
|
@ -15,7 +15,6 @@
|
||||||
* [Layers](#layers)
|
* [Layers](#layers)
|
||||||
* [Links](#links)
|
* [Links](#links)
|
||||||
* [Volumes](#volumes)
|
* [Volumes](#volumes)
|
||||||
* [Load/Save Import/Export](#loadsave-importexport)
|
|
||||||
* [Exposing Ports](#exposing-ports)
|
* [Exposing Ports](#exposing-ports)
|
||||||
* [Best Practices](#best-practices)
|
* [Best Practices](#best-practices)
|
||||||
* [Security](#security)
|
* [Security](#security)
|
||||||
|
|
@ -168,6 +167,35 @@ Images are just [templates for docker containers](https://docs.docker.com/engine
|
||||||
|
|
||||||
While you can use the `docker rmi` command to remove specific images, there's a tool called [docker-gc](https://github.com/spotify/docker-gc) that will clean up images that are no longer used by any containers in a safe manner.
|
While you can use the `docker rmi` command to remove specific images, there's a tool called [docker-gc](https://github.com/spotify/docker-gc) that will clean up images that are no longer used by any containers in a safe manner.
|
||||||
|
|
||||||
|
### Load/Save image
|
||||||
|
|
||||||
|
Load an image from file:
|
||||||
|
```
|
||||||
|
docker load < my_image.tar.gz
|
||||||
|
```
|
||||||
|
|
||||||
|
Save an existing image:
|
||||||
|
```
|
||||||
|
docker save my_image:my_tag > my_image.tar.gz
|
||||||
|
```
|
||||||
|
|
||||||
|
### Import/Export container
|
||||||
|
|
||||||
|
Import a container as an image from file:
|
||||||
|
```
|
||||||
|
cat my_container.tar.gz | docker import - my_image:my_tag
|
||||||
|
```
|
||||||
|
|
||||||
|
Export an existing container:
|
||||||
|
```
|
||||||
|
docker export my_container > my_container.tar.gz
|
||||||
|
```
|
||||||
|
|
||||||
|
### Difference between loading a saved image and importing an exported container as an image ?
|
||||||
|
|
||||||
|
Loading an image using the `load` command creates a new image including its history.
|
||||||
|
Importing a container as an image using the `import` command creates an new image excluding the history which results in a smaller image size compared to loading an image.
|
||||||
|
|
||||||
## Networks
|
## Networks
|
||||||
|
|
||||||
Docker has a [networks](https://docs.docker.com/engine/userguide/networking/dockernetworks/) feature. Not much is known about it, so this is a good place to expand the cheat sheet. There is a note saying that it's a good way to configure docker containers to talk to each other without using ports. See [working with networks](https://docs.docker.com/engine/userguide/networking/work-with-networks/) for more details.
|
Docker has a [networks](https://docs.docker.com/engine/userguide/networking/dockernetworks/) feature. Not much is known about it, so this is a good place to expand the cheat sheet. There is a note saying that it's a good way to configure docker containers to talk to each other without using ports. See [working with networks](https://docs.docker.com/engine/userguide/networking/work-with-networks/) for more details.
|
||||||
|
|
@ -333,41 +361,6 @@ You can also use remote NFS volumes if you're [feeling brave](https://web.archiv
|
||||||
|
|
||||||
You may also consider running data-only containers as described [here](http://container42.com/2013/12/16/persistent-volumes-with-docker-container-as-volume-pattern/) to provide some data portability.
|
You may also consider running data-only containers as described [here](http://container42.com/2013/12/16/persistent-volumes-with-docker-container-as-volume-pattern/) to provide some data portability.
|
||||||
|
|
||||||
## Load/Save Import/Export
|
|
||||||
|
|
||||||
Docker allows you to load/save images and import/export containers.
|
|
||||||
|
|
||||||
### Load/Save image
|
|
||||||
|
|
||||||
Load an image from file:
|
|
||||||
```
|
|
||||||
docker load < my_image.tar.gz
|
|
||||||
```
|
|
||||||
|
|
||||||
Save an existing image:
|
|
||||||
```
|
|
||||||
docker save my_image:my_tag > my_image.tar.gz
|
|
||||||
```
|
|
||||||
|
|
||||||
### Import/Export container
|
|
||||||
|
|
||||||
Import a container as an image from file:
|
|
||||||
```
|
|
||||||
cat my_container.tar.gz | docker import - my_image:my_tag
|
|
||||||
```
|
|
||||||
|
|
||||||
Export an existing container:
|
|
||||||
```
|
|
||||||
docker export my_container > my_container.tar.gz
|
|
||||||
```
|
|
||||||
|
|
||||||
### Difference between loading a saved image and importing an exported container as an image ?
|
|
||||||
|
|
||||||
Loading an image using the `load` command creates a new image including its history.
|
|
||||||
Importing a container as an image using the `import` command creates an new image excluding the history which results in a smaller image size compared to loading an image.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Exposing ports
|
## Exposing ports
|
||||||
|
|
||||||
Exposing incoming ports through the host container is [fiddly but doable](https://docs.docker.com/reference/run/#expose-incoming-ports).
|
Exposing incoming ports through the host container is [fiddly but doable](https://docs.docker.com/reference/run/#expose-incoming-ports).
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue