Update README.md

This commit is contained in:
Michael Currin 2021-09-11 15:31:13 +02:00 committed by GitHub
parent 8f9634a5bb
commit 06ceeaa164
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -497,16 +497,20 @@ Exposing incoming ports through the host container is [fiddly but doable](https:
This is done by mapping the container port to the host port (only using localhost interface) using `-p`: This is done by mapping the container port to the host port (only using localhost interface) using `-p`:
```sh ```sh
docker run -p 127.0.0.1:$HOSTPORT:$CONTAINERPORT --name CONTAINER -t someimage docker run -p 127.0.0.1:$HOSTPORT:$CONTAINERPORT \
--name CONTAINER \
-t someimage
``` ```
You can tell Docker that the container listens on the specified network ports at runtime by using [EXPOSE](https://docs.docker.com/engine/reference/builder/#expose): You can tell Docker that the container listens on the specified network ports at runtime by using [EXPOSE](https://docs.docker.com/engine/reference/builder/#expose):
``` ```Dockerfile
EXPOSE <CONTAINERPORT> EXPOSE <CONTAINERPORT>
``` ```
Note that EXPOSE does not expose the port itself -- only `-p` will do that. To expose the container's port on your localhost's port: Note that `EXPOSE` does not expose the port itself - only `-p` will do that.
To expose the container's port on your localhost's port, run:
```sh ```sh
iptables -t nat -A DOCKER -p tcp --dport <LOCALHOSTPORT> -j DNAT --to-destination <CONTAINERIP>:<PORT> iptables -t nat -A DOCKER -p tcp --dport <LOCALHOSTPORT> -j DNAT --to-destination <CONTAINERIP>:<PORT>
@ -798,20 +802,17 @@ docker images -viz | dot -Tpng -o docker.png
### Slimming down Docker containers ### Slimming down Docker containers
- Cleaning APT in a RUN layer - Cleaning APT in a `RUN` layer - This should be done in the same layer as other `apt` commands. Otherwise, the previous layers still persist the original information and your images will still be fat.
This should be done in the same layer as other apt commands.
Otherwise, the previous layers still persist the original information and your images will still be fat.
```Dockerfile ```Dockerfile
RUN {apt commands} \ RUN {apt commands} \
&& apt-get clean \ && apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
``` ```
- Flatten an image - Flatten an image
```sh ```sh
ID=$(docker run -d image-name /bin/bash) ID=$(docker run -d image-name /bin/bash)
docker export $ID | docker import flat-image-name docker export $ID | docker import flat-image-name
``` ```
- For backup - For backup
```sh ```sh
ID=$(docker run -d image-name /bin/bash) ID=$(docker run -d image-name /bin/bash)