Docker: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Geist (Diskussion | Beiträge) |
Geist (Diskussion | Beiträge) |
||
Zeile 303: | Zeile 303: | ||
'''$ docker run -it alpine /bin/sh''' | '''$ docker run -it alpine /bin/sh''' | ||
'''$ docker run -it busybox sh ''' | '''$ docker run -it busybox sh ''' | ||
+ | |||
+ | ''run interactive and remove container'' | ||
+ | '''$ docker run -it --rm busybox ''' | ||
+ | '''$ docker run -it --rm redis redis-cli ''' | ||
+ | '''$ docker run -it --rm busybox /bin/sh ''' | ||
+ | |||
+ | ''run interactive entrypoint'' | ||
+ | '''$ docker run -it --entrypoint /bin/sh bash''' | ||
+ | '''$ docker run -it --name mybash --entrypoint /bin/sh bash''' | ||
+ | '''$ docker run -it --name MYALPINE -p 8080:80 --entrypoint /bin/sh alpine''' | ||
===== RUN in the detached mode '''-d'''===== | ===== RUN in the detached mode '''-d'''===== | ||
Zeile 326: | Zeile 336: | ||
''run alpine cli detached'' | ''run alpine cli detached'' | ||
$''' docker run -it -d --name MYALPINE -p 8080:80 alpine''' | $''' docker run -it -d --name MYALPINE -p 8080:80 alpine''' | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
''EXEC'' | ''EXEC'' |
Version vom 22. März 2022, 17:32 Uhr
Tutorial docker, docker container, docker cli, docker-compose, docker swarm
- Automatisiertes Deployment - Durch automatisierte Builds - Isolierung von Systemen für mehr Sicherheit - Einfaches Deployment von Third-Party Software - Skalierung Docker keywords - dokku - docker compose - docker machine - docker daemon - docker swarm - docker node - docker service - docker stack - docker secret
Docker OLD | alias bashrc alias d='docker' alias dv='docker --version' alias dp='docker ps' alias dpa='docker ps -a' alias di='docker images' alias ds='docker search' alias dsi='docker system information' alias dsd='docker system df'
Inhaltsverzeichnis
- 1 Docker links
- 2 Docker system start|stop|enable|disable
- 3 Docker child commands description
- 4 Docker system information
- 5 Docker location | change docker location
- 6 Status | running containers | runned containers
- 7 Real time status
- 8 Images SEARCH|PULL|LIST|HISTORY
- 9 Delete Container/Images
- 10 Export
- 11 Volume
- 12 Network
- 13 docker run images
- 14 docker image run container
Docker links
Docker Docker hub Install Docker Engine on Debian Docker Registry HTTP API V2
Docker system start|stop|enable|disable
$ systemctl start docker $ systemctl stop docker $ systemctl enable docker $ systemctl disable docker
Docker child commands description
https://docs.docker.com/engine/reference/commandline/docker/
Docker system information
Version $ docker -v $ docker-compose -v
System $ docker system info
docker disk usage $ docker system df
real time events from the server $ docker system events
Docker location | change docker location
$ systemctl stop docker $ nano daemon.json { "data-root": "/MYPATH" }
$ rsync -aP /var/lib/docker/ /MYPATH $ cp -var /var/lib/docker/ /MYPATH
$ mv /var/lib/docker /var/lib/docker.old
$ systemctl stop docker
$ rm -rf /var/lib/docker.old
Status | running containers | runned containers
docker ps description
$ docker ps $ docker ps --all $ docker ps -a $ docker ps -l $ docker ps -n=2 $ docker ps -n=2 -s $ docker ps -as $ docker container ls -a $ docker ps -a -f status=running $ docker ps -aq
$ docker ps * -a, --all[=false] Show all containers (default shows just running) -f, --filter= Filter output based on conditions provided --format="" Pretty-print containers using a Go template -h, --help[=false] help for ps -n, --last=-1 Show n last created containers (includes all states) -l, --latest[=false] Show the latest created container (includes all states) --no-trunc[=false] Don't truncate output -q, --quiet[=false] Only display numeric IDs -s, --size[=false] Display total file sizes
Real time status
$ docker stats $ docker top [CONTAINER]
Images SEARCH|PULL|LIST|HISTORY
Docker image controll docker image description
Image commands $ docker image build # history # import # inspect # load # ls # prune # pull # push # rm # save # tag #
docker image build Build an image from a Dockerfile
docker image history Show the history of an image
docker image import Import the contents from a tarball to create a filesystem image
docker image inspect Display detailed information on one or more images
docker image load Load an image from a tar archive or STDIN
docker image ls List images
docker image prune Remove unused images
docker image pull Pull an image or a repository from a registry
docker image push Push an image or a repository to a registry
docker image rm Remove one or more images
docker image save Save one or more images to a tar archive (streamed to STDOUT by default)
docker image tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
Suche im Docker HUB nach Images docker search description $ docker search [NAME]
Download image docker pull description $ docker pull [NAME]
View all Images $ docker images $ docker image list $ docker image ls $ docker images --digests $ docker images * -a, --all[=false] Show all images (default hides intermediate images) -q, --quiet[=false] Only show numeric IDs --digests[=false] Show digests -h, --help[=false] help for images -f, --filter= Filter output based on conditions provided --format="" Pretty-print images using a Go template --no-trunc[=false] Don't truncate output
View Image by name $ docker images alpine $ docker images history [IMAGENAME] $ docker images --digests Image history $ docker image history [NAME] or [IMAGE ID] $ docker images -aq $ docker images rm $(docker ps -aq)
docker clean/check system $ docker system prune $ docker system prune --volumes
Delete Container/Images
$ docker rm [CONTAINER-ID]
$ docker rm $(docker ps -qa)
$ docker container rm [CONTAINER ID]
$ docker container rm $(docker ps -aq)
$ docker container kill [CONTAINER ID]
$ docker rm $(docker ps -a -q -f status=exited)
$ docker container prune
$ docker image rm [NAME]
$ docker image prune
Delete all local images docker rmi description $ docker rmi -f $(docker images -a -q) $ docker rmi XNAMEX $ docker rmi test:latest $ docker rmi -f test:latest
Export
export container, these commands has the same result $ docker export nginx > nginx_latest.tar $ docker export --output="nginx_latest" nginx
Volume
$ docker volume ls
Network
Networking overview $ docker network ls $ docker network create my-network default bridge $ docker network create --driver bridge my-network $ docker network inspect my-network $ docker network inspect bridge $ $ $ Configure the default bridge network To configure the default bridge network, you specify options in daemon.json. Here is an example daemon.json with several options specified. Only specify the settings you need to customize. { "bip": "192.168.1.5/24", "fixed-cidr": "192.168.1.5/25", "fixed-cidr-v6": "2001:db8::/64", "mtu": 1500, "default-gateway": "10.20.1.1", "default-gateway-v6": "2001:db8:abcd::89", "dns": ["10.20.1.2","10.20.1.3"] }
docker run images
$ docker run --help $ docker run -d --TABTAB
docker run [OPTIONS] IMAGE [COMMAND] [ARG...] $ docker run -it # interactively -d # detached ---ip 172.17.0.2 # Set Network first, only ip not work --hostname # aaaa.de -p 172.17.0.2:1010:80 # define external port and ip -p 8080:80 # define external port --name MYNAME # define container name -m 300m # memory limit --memory-swap 1g # --cpuset-cups="1" # -rm # auto remove container after exit --workdir "/home" # Any RUN , CMD , ADD , COPY , or ENTRYPOINT command will be executed in the specified working directory -w="/home" # ^ -v source:target # Mount or bind Volume/Directory -v Apache:/var/www/html -v "$PWD":/var/www/html
docker image run container
SINGLE RUN & COMMAND
$ docker run bash echo "WELCOME" $ docker run bash ping localhost $ docker run bash ip a $ docker run bash hostname $ docker run bash echo WELCOME && echo HELLO $ docker run bash echo WELCOME ; echo HELLO $ docker run bash /bin/sh -c "ls -1 | wc -l" $ docker run busybox echo "BUSYBOX"
run command and remove container $ docker run --rm bash hostname
RUN interactive & allocate a pseudo-tty
--interactive, -i keep STDIN open even if not attached -t: allocate a pseudo-tty $ docker run -it bash /bin/sh $ docker run -it busybox /bin/sh $ docker run -it --name mybash bash /bin/sh $ docker run -it alpine /bin/sh $ docker run -it busybox sh
run interactive and remove container $ docker run -it --rm busybox $ docker run -it --rm redis redis-cli $ docker run -it --rm busybox /bin/sh
run interactive entrypoint $ docker run -it --entrypoint /bin/sh bash $ docker run -it --name mybash --entrypoint /bin/sh bash $ docker run -it --name MYALPINE -p 8080:80 --entrypoint /bin/sh alpine
RUN in the detached mode -d
BASH
Start a bash container|restart always $ docker run -d --name bash-single --restart=always bash $ docker update --restart=always [CONTAINER ID] $ docker update --restart=on-failure [CONTAINER ID]
APACHE
$ docker run -d -p 1111:80 --name apache-single -v "$PWD":/var/www/html httpd
APACHE/PHP
$ docker run -dit -p 1000:80 --name apache-php-5 -v "$PWD":/var/www/html php:5-apache $ docker run -dit -p 1001:80 --name apache-php-7 -v "$PWD":/var/www/html php:7-apache $ docker run -dit -p 1002:80 --name apache-php-8 -v "$PWD":/var/www/html php:8-apache
$ docker run -p 5000:80 -d nginx
$ docker run -itd --name alpine1 -v $(pwd):/home alpine
run alpine cli detached
$ docker run -it -d --name MYALPINE -p 8080:80 alpine
EXEC
$ docker exec -it [container-name/id] /bin/sh
Volume/Directory
$ docker run -it --name MYALPINE -v ${PWD}:/home alpine
$ docker run -it --name MYALPINE -w='/home' -v ${PWD}:/home alpine
$ docker run -it --name MYALPINE --entrypoint /bin/sh --workdir '/home' -v ${PWD}:/home alpine
docker bash stop/kill images
$ docker stop [CONTAINER]
$ docker kill [CONTAINER]
BACKUP IMAGE, CONTAINER VOLUME
Image commit
$ docker commit [RUNNING_CONTAINER_ID] [MY_NEW_IMAGE_NAME] $ docker commit alpine1 alpine:v1 Create Image from running container
Image save
$ docker save busybox > busybox.tar Save one or more images to a tar archive
Image load
$ docker load < busybox.tar Load an image from a tar archive or STDIN
Container export
$ docker export alpine > alpinebkp.tar $ docker export --output="latest.tar" red_panda Export a container’s filesystem as a tar archive. The docker export command does not export the contents of volumes associated with the container.
Tar filesystem > Image import
$ cat alpine1.tar | docker import - alpine2:v2 Import the contents from a tarball to create a filesystem image
Volume, bind/mount, tmpfs mount
If your container generates non-persistent state data, consider using a tmpfs mount to avoid storing the data anywhere permanently, and to increase the container’s performance by avoiding writing into the container’s writable layer.
Volumes use rprivate bind propagation, and bind propagation is not configurable for volumes. In general, --mount is more explicit and verbose. The biggest difference is that the -v syntax combines all the options together in one field, while the --mount syntax separates them.
If you need to specify volume driver options, you must use --mount.
copy data container in /out
To copy a file from the local file system to a container, run the command for Docker container or Kubernetes pod, respectively: docker cp <src-path> <container>:<dest-path> To copy a file from the container to the local file system, use: docker cp <container>:<src-path> <local-dest-path>
'Docker Builder cache
$ docker builder prune
docker File
docker compose
docker network COMMAND
docker create
- create volume
docker volume create [OPTIONS] [VOLUME]
docker start -a xxx
docker start
docker run -d --name some-ghost -v Ghost-Blog:/var/lib/ghost/content ghost
docker run -d --name some-ghost -v Ghost-Blog:/var/lib/ghost/content -e url=http://192.168.109.152:3001 -p 3001:2368 ghost
docker attach [CONTAINER_ID]