wtsang11 / TechExplore

MIT License
0 stars 0 forks source link

Introduction #163

Open wtsang11 opened 3 years ago

wtsang11 commented 3 years ago

http://localhost/TechNotes/wp-admin/post.php?post=1409&action=edit

VSC: http://localhost/lab/python/utilities/study_codes/opencodes.php?f=/Users/wtsang/Lab/docker/hands_on_with_docker/

wtsang11 commented 3 years ago

Alpine python can make app slow

see https://pythonspeed.com/articles/alpine-docker-python/

wtsang11 commented 3 years ago

3 Forms of CMD in DockerFile

Ref: https://docs.docker.com/engine/reference/builder/

There are 3 forms of CMD in Dockerfile: The CMD instruction has three forms:

  1. CMD ["executable","param1","param2"] (exec form, this is the preferred form)
  2. CMD ["param1","param2"] (as default parameters to ENTRYPOINT)
  3. CMD command param1 param2 (shell form) There can only be one CMD instruction in a Dockerfile. If you list more than one CMD then only the last CMD will take effect.

The main purpose of a CMD is to provide defaults for an executing container. These defaults can include an executable, or they can omit the executable, in which case you must specify an ENTRYPOINT instruction as well.

If CMD is used to provide default arguments for the ENTRYPOINT instruction, both the CMD and ENTRYPOINT instructions should be specified with the JSON array format.

wtsang11 commented 3 years ago

Inspect an image

docker image inspect

delete an image

docker image rm

push an image web1 to hub

docker login docker image tag web1 wtsang/web1:latest docker image push wtsang/web1:latest -- wtsang = username, web1 = repo name docker pull wtsang/web1:latest

wtsang11 commented 3 years ago

running container

docker container run -it --rm --name web1 -p 5000:5000 -e FLASK_APP=app.py -d web1 -- see its log docker container logs web1 -- running another container on the same image -- note that the published port is given but the assigned port is dynamic -- note a different container name is given docker container run -it --rm --name web1 -p 5000 -e FLASK_APP=app.py -d web1_2 -- run a third container using restart flag such that remove flag cannot be used docker container run -it --restart --name web1 -p 5000 -e FLASK_APP=app.py -d web1_3 -- see the statistics docker container stats -- with debugging -- code changes eg in app.py will be hot reloaded docker container run -it -p 5000 -e FLASK_APP=app.py -e FLASK_DEBUG=1 --rm --name web1 -v $PWD:/app web1

wtsang11 commented 3 years ago

Debugging Tips