0% found this document useful (0 votes)
217 views6 pages

Docker Notes

This document provides examples of Docker commands for running, managing, and inspecting containers. Some key commands covered include docker container run to start a container, docker container ls to list containers, docker container logs to view logs, and docker container inspect to view detailed container information. It also discusses using flags like -d for detached mode and -p to publish ports. Images can be built with docker image build and viewed with docker image ls. Docker volumes and networking are also briefly explained.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
217 views6 pages

Docker Notes

This document provides examples of Docker commands for running, managing, and inspecting containers. Some key commands covered include docker container run to start a container, docker container ls to list containers, docker container logs to view logs, and docker container inspect to view detailed container information. It also discusses using flags like -d for detached mode and -p to publish ports. Images can be built with docker image build and viewed with docker image ls. Docker volumes and networking are also briefly explained.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

ch2

docker container run --interactive --tty diamol/base


--interactive = set up connection to container
--tty = connect to a terminal session

/ # hostname
f1695de1f2ec
/ # date
Thu Jun 20 12:18:26 UTC 2019

docker container ls = show running containers

docker container ls --all = show running and not active containers


docker container ls -a = show running and not active containers

docker container top f169 = lists processes inside container

docker container logs f169 = lists logs of actions inside container

docker container inspect f169 = shows detailed info about container

run to start the app, logs to read out the logs, top to see the
processes, and inspect to get the details.

docker container run --detach --publish 8088:80 diamol/ch02-hello-


diamol-web
--detach = Starts the container in the background and shows the container ID
--publish = Publishes a port from the container to the computer

docker container run -P = take all ports form container and connect to random port
on host computer

docker container ps = show working containers and their details

docker container rm --force $(docker container ls --all --quiet) = finish all

ch3

docker container run -d --name web-ping diamol/ch03-web-ping


-d flag is a short form of --detach, so this container will run in the background
--name is our friendly name given to container

atrl-C to stop pining

docker rm -f web-ping = remove existing container


docker container run --env TARGET=google.com diamol/ch03-web-ping = run container
with environment variable TARGET set to new value for ping

docker image build --tag web-ping . = build new docker image from files from
current directory "." and the name of images comes from --tag web-ping

docker image ls 'w*' = List all the images where the tag name starts with �w�:

docker image ls = lists all the images

docker system df = shows how much disk space Docker is using

Any Dockerfile you write should be optimized so that the instructions are ordered
by how frequently they change�with instructions that are unlikely to change at the
start of the Dockerfile, and instructions most likely to change at the end.

cd ../web-ping-optimized = go to previus folders

localhost = http://192.168.99.100:8080/

ch 01 master docker book

FROM alpine:latest = choose base image which is operating system linux alpine with
latest version.

docker image build --tag local:fromscratch . = locate the folder with dockerfile
using cd command in powershell and then run command, local = local repository,
fromscratch = name of the image.

Docer shipswith several built-in drivers, known as native drivers or local drivers.
On Linux they include; bridge,
overlay, and macvlan. On Windows they include; nat, overlay, transparent, and
l2bridge.

Docker volumes:
docker container run -d --name tolik -v /c/Users/Greg/filess:/app nginx
docker container run -d --name tolik --mount
'type=volume,source=filesss,target=/app' nginx

C:\Users\Greg\filess = ����������� � /c/Users/Greg/filess

try to run it with additional / for volume like:

docker run -d --name simple2 -v /c/Users/src://usr/share/nginx/html -p 8082:80 ng1

Or even for host OS, as

docker run -d --name simple2 -v //c/Users/src://usr/share/nginx/html -p 8082:80 ng1

Chapter 2#
FROM ubuntu:20.04
FROM scratch

LABEL <key>=<value>
LABEL [email protected] version=1.0 environment=dev

The RUN directive can be used to install


the required packages, update the packages, create users and groups, and so on.

apt-get update is used to update the package repositories


apt-get install nginx -y is used to install the Nginx package:
RUN apt-get update && apt-get install nginx -y

CMD ["executable","param1","param2","param3", ...]


ENTRYPOINT ["executable","param1","param2","param3", ...]

ENV <key> <value>


ENV PATH $PATH:/usr/local/myapp/bin/

ENV <key>=<value> <key>=<value> ...


ENV PATH=$PATH:/usr/local/myapp/bin/ VERSION=1.0.0

$ docker image build -t <image>:<tag> --build-arg <varname>=<value> .

ARG <varname>

ARG USER
ARG VERSION
ARG USER=TestUser
ARG VERSION=1.0.0

CMD ["env"] = which will print all the environment variables.

WORKDIR /path/to/workdir = current working directory, will be created if not exist

WORKDIR /one
WORKDIR two
WORKDIR three
RUN pwd

/one/two/three.

COPY <source> <destination>


ADD http://sample.com/test.txt /tmp/test.txt
ADD html.tar.gz /var/www/html
USER <user>
USER <user>:<group>

The www-data user is the default user for the Apache web server
on Ubuntu.

VOLUME ["/path/to/volume"]
VOLUME /path/to/volume1 /path/to/volume2

ENV DEBIAN_FRONTEND=noninteractive

"Source": "/mnt/sda1/var/lib/docker/volumes/a600c1d8a
EXPOSE <port>
docker container run -p <host_port>:<container_port> <image>

HEALTHCHECK [OPTIONS] CMD command


HEALTHCHECK CMD curl -f http://localhost/ || exit 1

ONBUILD <instruction>

When building an image from a Dockerfile, layers are created when the RUN,ADD, and
COPY commands are used.

docker history <image_name|image_id>

docker image inspect <image_id>


cat <image_tar_file_name> | docker import - <new_image_name>

du -sh /var/lib/docker/overlay2/ = check disk space usage by images

docker tag <source_repository_name>:<tag> <target_repository_name>:tag


docker build -t <dockerhub_user>/<target_repository_name>:tag Dockerfile
docker tag 19485c79a9bb new_busybox:ver_1
docker tag new_busybox:ver_1 vince/busybox:ver_1.1

major_version.minor_version.patch

docker save -o <output_file_and_Directory> <image_repo_name/image_


name:tag>

docker save -o /tmp/basic-app.tar vincesestodocker/basic-app:1.0.0

<account_name>/<image_name>:tag

docker tag basic-app vincesestodocker/basic-app:ver1

docker push vincesestodocker/basic-app:ver1


denied: requested access to the resource is denied
docker login
docker push basic-app vincesestodocker/basic-app:ver1

git log --pretty=format:"%h"

docker image build --target builder -t multi-stage-dev:v1 .

--user (or -u) flag, and with the USER directive.

docker run --user=9999 ubuntu:focal

FROM ubuntu:focal
RUN apt-get update
RUN useradd demo-user
USER demo-user
CMD whoami

he following is the content of a sample .dockerignore file:


PASSWORDS.txt
tmp/
*.md
!README.md
In the preceding example, we have specifically excluded the PASSWORDS.txt file
and tmp directory from the build context, as well as all files with the .md
extension
except for the README.md file.

FROM ubuntu:focal
RUN apt-get update \
&& apt-get install --no-install-recommends -y nginx

FROM ubuntu:focal
RUN apt-get update \
&& apt-get install --no-install-recommends -y nginx \
&& rm -rf /var/lib/apt/lists/*

server:
env_file:
- database.env

networking on the container host (underlay networking)


networking
between containers on the same host or within different clusters (overlay
networking).

$ docker run -itd --network dnsnet --network-alias alpinedns2 --name


alpinedns2 alpine:latest

$ docker run -itd --name containerlink2 --link containerlink1


alpine:latest

$ docker network create -d macvlan --subnet=192.168.122.0/24


--gateway=192.168.122.1 -o parent=enp1s0 macvlan-net1

docker swarm init

docker swarm join --token <swarm_token> <ip_address>:<port>

docker swarm join-token --rotate

docker node ls
docker service create --name <service> <image> <command>
docker service update <service> <changes>
docker service remove <service>
docker service scale web=3
docker node update --availability drain j2qxrpf0a1yhvcax6n2ajux69

docker node demote <node_id> = if node is manager


docker node rm <node_id>
docker node rm --force <node_id>
ocker node inspect <node_id>
docker stack deploy --compose-file <compose_file> <swarm_name>
docker stack ps <swarm_name>
docker stack rm <swarm_name>
docker service update --image <image_name:tag> <service_name>
docker config create <config_name> <configuration_file>
docker config inspect --pretty <config_name>
echo "<secret_password>" | docker secret create <secret_name> �
docker secret create <secret_name> <secret_file>
docker secret ls
echo "docker" | docker secret create pg_password �

You might also like