Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 11

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

Service-oriented architecture: distribute the app on multi containers

- Containers - Running instances of Docker images

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 run -> create a container


/var/lib/docker/, including images, containers, volumes, and networks, are
preserved. The Docker CE package is now called docker-ce.

-----------------------------------------------------------------------------------
---------

Docker Container
=================

- docker [container]run []-> optional


* --interactive -> -i
* --tty #terminal# -> -t
* --hostname= -> -h -> default hostmane == container_id
* --name=<value> || --name <value>
* --rm Automatically remove the container when it
exits
* --volume -> -v -> work like sshfs tpically -v /mnt/log:/var/log/nignx
* --publish #port# -> -p -> work like port_forwarding tpically -p 5000:80
#host_port:container_port#
By default, the port on the host is mapped to 0.0.0.0, which means all IP
addresses. You can specify a particular IP address when you define the port
mapping, for example, -p 127.0.0.1:8080:80
* -p -> 80 == EXPOSE 80 connect a ramdom port (to know it use: docker ps -a)
on host to port 80 on container
* --detach -> -d -> still play however exit it => to connect with container
should use <docker exec>
* --user -u (root | 0 | sabry )
* --env -e -> environment variable
* --restart=always
* --mount type=bind,source="$(pwd)",target=/usr/share/nginx/html #Bind mounts
mean that any changes
made to the local file system are
immediately reflected in the
running container#
* <excute_command_inside_the_container> ls -la

- docker container (ls|ps) == docker ps -> run containers only


- docker container (ls|ps) -a == docker ps -a -> all containers
- docker container start <container_ID> -ia [interactive] [attach]
- docker container restart <container_ID>
- docker container pause <container_ID>
- docker container stop <container_ID>
- docker container exec <container_id> <command>
- docker container diff <container_id>
- docker container commit <container_id> -> add above base image
- docker container commit <container_id> --author [-a] sabry <new_image_name>
- docker container logs -> show logs
- docker container top -> show prosess
- docker container stop $(docker container ls --all [-a] --quiet [-q]) --all = up
+ existed --quiet = print id only
- docker container rm --force [-f] $(docker container ls -aq)
- Ctrl-P + Ctrl-q exit a container and still running

docer search coreos -> search in docker hub

-v /path:/path/in/container => mount /path at host machine with path in container


-v path:/path/in/container => create a volume path

-----------------------------------------------------------------------------------
---------
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

create Create a volume


inspect Display detailed information on one or more volumes
ls List volumes
prune Remove all unused volumes
rm Remove one or more volumes

* 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

Usage: docker network COMMAND

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

Run 'docker network COMMAND --help' for more information on a command.

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 : docker container run ping:v0.1 8.8.8.8 -> 8.8.8.8 is a 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

docker image build -t hello:v0.1 .

* Lightweight Dstributions :-
- alpine -> apk -> package manager
- busybox
- coreos

.dockerignore

# comment
*/temp*
*/*/temp*
temp?
*.md
!README.md
-----------------------------------------------------------------------------------
---------

- when you <exit> from a container you will shutdown it


- when you create a container from image the container have automaticly <id> &&
<name>

* Terminology
----------------

- Layers - A Docker image is built up from a series of layers. Each layer


represents an instruction in the image’s Dockerfile. Each layer except the
last one is read-only.
- Dockerfile - A text file that contains all the commands, in order, needed to
build a given image. The Dockerfile reference page lists the various commands
and format details for Dockerfiles.
- Volumes - A special Docker container layer that allows data to persist and be
shared separately from the container itself. Think of volumes as a way to
abstract and manage your persistent data separately from the
application itself.

- docker :-
- login
- logout
- rm -> for containers
- rmi -> for images

- Docker Cloud
- Docker Store
- Docker Hub

* There are different ways to use containers. These include:

- To run a single task: This could be a shell script or a custom app.


- Interactively: This connects you to the container similar to the way you SSH into
a remote server.
- In the background: For long-running services like websites and databases.
-----------------------------------------------------------------------------------
---------

docker-compose
===============

- docker-compose build
- docker-compose up -d

- First Alpine Linux Containers


- Doing More With Docker Images
- Docker for Beginners - Linux
- Docker images deeper dive

- Node.js with SQL Server on Docker

/var/lib/docker/overlay2 folder where the image and container layers are stored

What are Moby and LinuxKit?

- Moby: An open framework to assemble specialized container systems without


reinventing the wheel.

and:

- LinuxKit, a toolkit for building custom minimal, immutable Linux distributions.

docker info

‫ملحظة ثانية مشروع كور أو أس‬


coreos
‫ أصبح تابع لمشروع‬atomic
‫تحت رعاية ريدهات‬

docker exec --ti x1 ps ax


- docker run -l user=12345 -d redis
- echo 'user=123461' >> labels && echo 'role=cache' >> labels
- docker run --label-file=labels -d redis
- LABEL vendor=Katacoda \
com.katacoda.version=0.0.5 \
com.katacoda.build-date=2016-07-01T10:47:29Z \
com.katacoda.course=Docker

- docker inspect -f "{{json .Config.Labels }}" rd


- docker inspect -f "{{json .ContainerConfig.Labels }}" katacoda-label-example
- docker images --filter "label=vendor=Katacoda"
- docker -d \
-H unix:///var/run/docker.sock \
--label com.katacoda.environment="production" \
--label com.katacoda.storage="ssd"

container_name:
property: value
- or options

docker-compose up -d
docker-compose up redis -d

docker-compose scale web=3

docker ps --format '{{.Names}} container is using {{.Image}} image'


docker ps --format 'table {{.Names}}\t{{.Image}}'
docker ps -q | xargs docker inspect --format '{{ .Id }} - {{ .Name }} - {{
.NetworkSettings.IPAddress }}'

Start Docker Containers on Boot with Systemd

Floating ip
Usage: docker COMMAND

A self-sufficient runtime for containers

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

Usage: docker container COMMAND

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

integration with vscode


------------------------
extentions:
- Docker {Microsoft} -> IntelliSense -> ctrl+space, tab,IntelliSense images search
at docker hub ,docker commands
- Docker Explorer {Jun Han} -> GUI control

- [r-brain](r-brain.io) -> { R + sql + python } online


- [google colab](http://xminers.club/2018/03/02/‫تستخدم‬-‫أن‬-‫يجب‬-‫لماذا‬-google-colab--‫في‬
‫القادمة‬-‫المرة‬/)
- [google CLOUD DATAPROC on Cloud Platform](https://cloud.google.com/dataproc/?
hl=ar)
- [floydhub](https://www.floydhub.com)

You might also like