Learning Docker
Docker General Knowledge
Common CLi
1 | # list all images in local |
Docker commit
1 | # save container to a image with your changes |
Options
Name, shorthand | Default | Description |
---|---|---|
--author , -a |
Author (e.g., “John Hannibal Smith [email protected]”) | |
--change , -c |
Apply Dockerfile instruction to the created image | |
--message , -m |
Commit message | |
--pause , -p |
true |
Pause container during commit |
How to SSH among multiple container
1 | # create three compute node |
Now, you can access one container from another container, like as follows:
1 | [root@937fa919cd2a /]# ssh [email protected] |
Docker network
1 | # list network |
Network drivers
Docker’s networking subsystem is pluggable, using drivers. Several drivers exist by default, and provide core networking functionality:
bridge
: The default network driver. If you don’t specify a driver, this is the type of network you are creating. Bridge networks are usually
used when your applications run in standalone containers that need to communicate. See bridge networks.host
: For standalone containers, remove network isolation between the container and the Docker host, and use the host’s networking
directly.host
is only available for swarm services on Docker 17.06 and higher. See use the host network.overlay
: Overlay networks connect multiple Docker daemons together and enable swarm services to communicate with each other. You can also use
overlay networks to facilitate communication between a swarm service and a standalone container, or between two standalone containers on different
Docker daemons. This strategy removes the need to do OS-level routing between these containers.
See overlay networks.macvlan
: Macvlan networks allow you to assign a MAC address to a container, making it appear as a physical device on your network. The Docker
daemon routes traffic to containers by their MAC addresses. Using themacvlan
driver is sometimes the best choice when dealing with legacy
applications that expect to be directly connected to the physical network, rather than routed through the Docker host’s network stack.
See Macvlan networks.none
: For this container, disable all networking. Usually used in conjunction with a custom network driver.none
is not available for swarm
services. See disable container networking.- Network plugins: You can install and use third-party network plugins with Docker. These
plugins are available from Docker Hub or from third-party vendors. See the vendor’s
documentation for installing and using a given network plugin.
Network driver summary
- User-defined bridge networks are best when you need multiple containers to communicate on the same Docker host.
- Host networks are best when the network stack should not be isolated from the Docker host, but you want other aspects of the container to be
isolated. - Overlay networks are best when you need containers running on different Docker hosts to communicate, or when multiple applications work together
using swarm services. - Macvlan networks are best when you are migrating from a VM setup or need your containers to look like physical hosts on your network, each with
a unique MAC address. - Third-party network plugins allow you to integrate Docker with specialized network stacks.
Filter and Format
1 | Filters |
FYI
Container
docker container my_command
create
- Create a container from an image.
start
- Start an existing container.
run
- Create a new container and start it.
ls
- List running containers.
inspect
- See lots of info about a container.
logs
- Print logs.
stop
- Gracefully stop running container.
kill
- Stop main process in container abruptly.
rm
- Delete a stopped container.
Image
docker image my_command
build
- Build an image.
push
- Push an image to a remote registry.
ls
- List images.
history
- See intermediate image info.
inspect
- See lots of info about an image, including the layers.
rm
- Delete an image.