Docker Basics
Benediktus Anindito
Cloud Computing
Terminologies
●
Container Image: a prebuilt template for
running container
●
Container: an virtual instance which has
separate namespace, operating system
libraries, which running inside a host system
Container Lifecycle
●
Here are lifecycle of a container
– Created: a container instance is created; ephemeral storage
is allocated; networking parameters is set; but it is not
started yet
– Running: a container instance is started and run its own
process
– Stopped: a container instance still exists but all its process is
killed.
– Deleted: a container instance is deleted and its ephemeral
storage is removed; networking parameters is also removed.
docker run basic parametes
● Syntax:
– Docker run <parameter1>…<parametern> <image-name:tag> [commandline]
● --name : set name for the new container
● -d : run in background (daemonized)
● -i : run with STDIN keep open
● -t : allocate a pseudo-TTY; usually run with -i
● -v </host/path>:</container/path> : add volume mount into container; can be specified more than once
● -p <host-port>:<container-port> : publish a listening port to host system
● -e ENV_VAR_NAME=value : add environment variable in the container
● Complete list [Link]
docker exec command¶m
●
Syntax
– docker exec <param>..<param> <container-name>
<commandline>
●
This command will execute <commandline> on
container <container-name>
●
Add `-i` and `-t` parameter to interact with the
execution
Docker compose manifest basics
●
Docker compose manifest consist of 1 file:
[Link] (or [Link] on
older version of docker-compose)
●
Consist of one mandatory section (services)
and some other sections (networks, volumes,
configs, secrets)
Services section
●
Key is service name
●
Each key contains several sub keys:
– container_name (set container name)
– image (container image to use)
– volumes (volume mounts, format is the same as -v)
– environments (environment variable, array with format
VARIABLE=value or set subkey VARIABLE with value)
– ports (expose port, format is same as -p)
– restart (restart policy, if host is restarted, should the container is
autostarted)
●
See more [Link]
vices/