Professional Documents
Culture Documents
Docker
Docker
=======
docker is containers manager
<!-- container can contain one Process only -->
docker download (bins & libs) only for any derstbution and share kernel with a host
service-oriented architecture : split any application work on docker to mote than
container and communicate with each other
docker :-
- engine
- image
- container
- volumes
- network
- registry
- store
- store
- commuinty (docker hub)
- plugins
- When you executed the command docker container run hello-world, it also did a
docker image pull behind the scenes to download the hello-world image.
-----------------------------------------------------------------------------------
---------
Docker Container
=================
-----------------------------------------------------------------------------------
---------
Docker Volume
==============
- docker volume
- create --name DataVolume1 -> free volume (not connected with any container)
- inspect
- ls
- prune
- rm
- --volumes-from Container4
- --volumes-from Container4:ro -> ro -> read only
* if we create a volume first then we attach it with a container --rm not remove
this volume
* HOST_PATH and CONTAINER_PATH can be a folder or file. HOST_PATH must exist before
running this command
-----------------------------------------------------------------------------------
---------
Docker Image
=============
- docker image
pull <image_name> alpine
- docker image
ls
- docker image
inspect <image_name> alpine
- docker image
rm <image_id>
- docker image
tag [-t] <image_id> ourfiglet
- docker image
build -t hello:v0.1 . #DockerID/application_name:version#
<repository>/<image>:<tag>
default :
library/<image>:latest
- docker image history <image_id>
- docker image inspect --format "{{ json .RootFS.Layers }}" <image_id>
- docker image ls --filter [-f] reference="$DOCKERID/*"
- docker image build --file [-f] Dockerfile-v2 -t hello:v0.2 . as we do not use
the default name for our
Dockerfile, we use the -f option to point
towards the one we need to use
Notice that several lines of the output say Layer already exists. This is because
Docker will leverage read-only layers that are the same as any previously uploaded
image layers.
-----------------------------------------------------------------------------------
---------
Docker Network
===============
- create
- connect
- disconnect
- inspect
- ls
- prune
- rm
Manage networks
Options:
--help Print usage
Commands:
connect Connect a container to a network
create Create a network
disconnect Disconnect a container from a network
inspect Display detailed information on one or more networks
ls List networks
prune Remove all unused networks
rm Remove one or more networks
The bridge network is the default network for new containers. This means that
unless you specify a different network, all new containers will be connected to the
bridge network.
-----------------------------------------------------------------------------------
---------
Dockerfile
===========
* commands :-
- FROM
- RUN
- COPY
- WORKDIR
- ENTRYPOINT ["ping"] -> main command
- CMD ["127.0.0.1"] -> can use as a command and can use as a argument
"parameter"
ex :-
FROM alpine
RUN apk update && apk add nodejs
COPY . /app
WORKDIR /app the directory the container should
use when it starts up
CMD ["node","index.js"] the commands which is run when the
container starts
* Lightweight Dstributions :-
- alpine -> apk -> package manager
- busybox
- coreos
.dockerignore
# comment
*/temp*
*/*/temp*
temp?
*.md
!README.md
-----------------------------------------------------------------------------------
---------
* Terminology
----------------
- docker :-
- login
- logout
- rm -> for containers
- rmi -> for images
- Docker Cloud
- Docker Store
- Docker Hub
docker-compose
===============
- docker-compose build
- docker-compose up -d
/var/lib/docker/overlay2 folder where the image and container layers are stored
and:
docker info
container_name:
property: value
- or options
docker-compose up -d
docker-compose up redis -d
Floating ip
Usage: docker COMMAND
Options:
--config string Location of client config files (default
"/home/scrapbook/.docker")
-D, --debug Enable debug mode
-H, --host list Daemon socket(s) to connect to
-l, --log-level string Set the logging level
("debug"|"info"|"warn"|"error"|"fatal") (default "info")
--tls Use TLS; implied by --tlsverify
--tlscacert string Trust certs signed only by this CA (default
"/home/scrapbook/.docker/ca.pem")
--tlscert string Path to TLS certificate file (default
"/home/scrapbook/.docker/cert.pem")
--tlskey string Path to TLS key file (default
"/home/scrapbook/.docker/key.pem")
--tlsverify Use TLS and verify the remote
-v, --version Print version information and quit
Management Commands:
config Manage Docker configs
container Manage containers
image Manage images
network Manage networks
node Manage Swarm nodes
plugin Manage plugins
secret Manage Docker secrets
service Manage services
swarm Manage Swarm
system Manage Docker
trust Manage trust on Docker images
volume Manage volumes
Commands:
attach Attach local standard input, output, and error streams to a running
container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes to files or directories on a container's filesystem
events Get real time events from the server
exec Run a command in a running container
export Export a container's filesystem as a tar archive
history Show the history of an image
images List images
import Import the contents from a tarball to create a filesystem image
info Display system-wide information
inspect Return low-level information on Docker objects
kill Kill one or more running containers
load Load an image from a tar archive or STDIN
login Log in to a Docker registry
logout Log out from a Docker registry
logs Fetch the logs of a container
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
ps List containers
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
- rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save one or more images to a tar archive (streamed to STDOUT by
default)
search Search the Docker Hub for images
start Start one or more stopped containers
- stats Display a live stream of container(s) resource usage statistics
[--no-stream]-> one_shot
stop Stop one or more running containers
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
version Show the Docker version information
wait Block until one or more containers stop, then print their exit codes
Manage containers
Options:
Commands:
attach Attach local standard input, output, and error streams to a running
container
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes to files or directories on a container's filesystem
exec Run a command in a running container
export Export a container's filesystem as a tar archive
inspect Display detailed information on one or more containers
kill Kill one or more running containers
logs Fetch the logs of a container
ls List containers
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
prune Remove all stopped containers
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
run Run a command in a new container
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
wait Block until one or more containers stop, then print their exit codes
you can use pipes and xargs. A pipe passes the output from one command into the
input of another while xargs allows you to provide this input as arguments to a