Sunday, September 8, 2019

docker cheat sheets

https://github.com/wsargent/docker-cheat-sheet


About "docker inspect". you can inspect a container or an image.


docker inspect $containerid

-> there are 2 places with "Image", one showing the image's sha2, the other the image's name.
If you use the sha2 to identify the image, remember it's truncated to the leftmost 12 digits.

docker image inspect $imagename (or $imagesha2)

here you find the Cmd and Entrypoint`


You can assign a label to image in Dockerfile:
LABEL app=hello-world

and use it to filter:

docker images --filter "label=app=hello-world"


since version 18.6 you can use BuildKit https://docs.docker.com/engine/reference/builder/#label :

without BuildKit:

docker build -t myhw .
Sending build context to Docker daemon  9.728kB
Step 1/3 : FROM busybox:latest
 ---> db8ee88ad75f
Step 2/3 : CMD echo "Hello world date=" `date`
 ---> Using cache
 ---> 22bd2fd85b95
Step 3/3 : LABEL app=hello-world
 ---> Running in 1350a308f4eb
Removing intermediate container 1350a308f4eb
 ---> 7a576b758d86
Successfully built 7a576b758d86
Successfully tagged myhw:latest


export DOCKER_BUILDKIT=1


with BuildKit:

docker build -t myhw .
[+] Building 2.2s (5/5) FINISHED                                                                                                                                                                                   
 => [internal] load .dockerignore                                                                                                                                                                             1.5s
 => => transferring context: 2B                                                                                                                                                                               0.0s
 => [internal] load build definition from Dockerfile                                                                                                                                                          1.2s
 => => transferring dockerfile: 181B                                                                                                                                                                          0.0s
 => [internal] load metadata for docker.io/library/busybox:latest                                                                                                                                             0.0s
 => [1/1] FROM docker.io/library/busybox:latest                                                                                                                                                               0.0s
 => => resolve docker.io/library/busybox:latest                                                                                                                                                               0.0s
 => exporting to image                                                                                                                                                                                        0.0s
 => => exporting layers                                                                                                                                                                                       0.0s
 => => writing image sha256:4ce77b76b309be143c25ad75add6cdf17c282491e2966e6ee32edc40f802b1f4                                                                                                                  0.0s
 => => naming to docker.io/library/myhw     



CMD vs ENTRYPOINT

if you use
ENTRYPOINT echo "pippo "
docker build -t echopippo .
docker run echopippo

it will print "pippo"

if you use also CMD
ENTRYPOINT echo "pippo "
CMD " peppo"

it will still print only "pippo". To append arguments, you must use the JSON array format (i.e. square brackets)

ENTRYPOINT ["echo", "pippo "]
CMD [" peppo"]


this will print "pippo peppo".

If you provide an extra parameter from command line:
docker run echopippo pluto

then CMD is ignored, and the parameter from command line is used:
pippo pluto




Priceless Romin Irani turorial on :

docker volumes: https://rominirani.com/docker-tutorial-series-part-7-data-volumes-93073a1b5b72

Dockerfile: https://rominirani.com/docker-tutorial-series-writing-a-dockerfile-ce5746617cd


Other tutorials here https://github.com/botchagalupe/DockerDo






No comments: