User Tools

Site Tools


devops:docker

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
devops:docker [2018/01/11 12:16] – [Host to Container connectivity] skipidardevops:docker [2025/03/22 23:03] (current) skipidar
Line 34: Line 34:
  
 == Commands == == Commands ==
-^ Command  ^ Description ^ +^ Command                                                                                                           ^ Description                                                                                                                                                                                                                                                                                                                                                                                                                                                              
-| commit | creates a new image from a container | +| commit                                                                                                            | creates a new image from a container                                                                                                                                                                                                                                                                                                                                                                                                                                     
-| run | runs a container from an image | +| run                                                                                                               | runs a container from an image                                                                                                                                                                                                                                                                                                                                                                                                                                           
-| start | starts an EXISTING, STOPPED container | +| start                                                                                                             | starts an EXISTING, STOPPED container                                                                                                                                                                                                                                                                                                                                                                                                                                    
-| stop | stops an EXISTING, RUINNING container | +| stop                                                                                                              | stops an EXISTING, RUINNING container                                                                                                                                                                                                                                                                                                                                                                                                                                    
-| exec | executes a command INSIDE of EXISTING, RUNNING container | +| exec                                                                                                              | executes a command INSIDE of EXISTING, RUNNING container                                                                                                                                                                                                                                                                                                                                                                                                                 
-| docker search NAME | Search for an image with the specified name. | +| docker search NAME                                                                                                | Search for an image with the specified name.                                                                                                                                                                                                                                                                                                                                                                                                                             
-| docker pull NAME | Pull an image into your local file system with he specified name. | +| docker pull NAME                                                                                                  | Pull an image into your local file system with he specified name.                                                                                                                                                                                                                                                                                                                                                                                                        
-| docker version | Prints the docker version to the standard output. | +| docker version                                                                                                    | Prints the docker version to the standard output.                                                                                                                                                                                                                                                                                                                                                                                                                        
-| docker run -td -p 80:8080 NAME | Run a docker image with daemon mode with port 80 forwarded to port 8080 in the container. | +| docker run -td -p 80:8080 NAME                                                                                    | Run a docker image with daemon mode with port 80 forwarded to port 8080 in the container.                                                                                                                                                                                                                                                                                                                                                                                
-| docker start CONTAINERID | Start a stopped container. | +| docker start CONTAINERID                                                                                          | Start a stopped container.                                                                                                                                                                                                                                                                                                                                                                                                                                               
-| docker stop CONTAINERID | Stop a container with the specified id. | +| docker stop CONTAINERID                                                                                           | Stop a container with the specified id.                                                                                                                                                                                                                                                                                                                                                                                                                                  
-| docker ps | List all RUNNING container | +| docker ps                                                                                                         | List all RUNNING container                                                                                                                                                                                                                                                                                                                                                                                                                                               
-| docker ps -a | List all container | +| docker ps -a                                                                                                      | List all container                                                                                                                                                                                                                                                                                                                                                                                                                                                       
-| docker login -u USERNAME -p PASSWORD -e EMAIL registryURL | Login to a registry with -u for username -p for password and -e for email. | +| docker login -u USERNAME -p PASSWORD -e EMAIL registryURL                                                         | Login to a registry with -u for username -p for password and -e for email.                                                                                                                                                                                                                                                                                                                                                                                               
-| docker rm CONTAINERID | Remove a container. | +| docker rm CONTAINERID                                                                                             | Remove a container.                                                                                                                                                                                                                                                                                                                                                                                                                                                      
-| docker images -a | list all images | +| docker images -a                                                                                                  | list all images                                                                                                                                                                                                                                                                                                                                                                                                                                                          
-| docker rmi IMAGEID | Remove an image. | +| docker rmi IMAGEID                                                                                                | Remove an image.                                                                                                                                                                                                                                                                                                                                                                                                                                                         
-| docker logs | Fetch the logs from a docker container. | +| docker logs                                                                                                       | Fetch the logs from a docker container.                                                                                                                                                                                                                                                                                                                                                                                                                                  
-| docker inspect IMAGE_NAME|echo JSON with describtion| +| docker inspect IMAGE_NAME                                                                                         | echo JSON with describtion                                                                                                                                                                                                                                                                                                                                                                                                                                               
-| docker run -d IMAGE_NAME | Detach. Means run in background. Even when you quit the container. Dont block the console with STDOUT. | +| docker run -d IMAGE_NAME                                                                                          | Detach. Means run in background. Even when you quit the container. Dont block the console with STDOUT.                                                                                                                                                                                                                                                                                                                                                                   
-| docker run -P IMAGE_NAME | expose ports on DOCKER_HOST. Port 5000 of container is redirected to localhost:5000| +| docker run -P IMAGE_NAME                                                                                          | expose ports on DOCKER_HOST. Port 5000 of container is redirected to localhost:5000                                                                                                                                                                                                                                                                                                                                                                                      
-| docker exec -it CONTAINERID COMMAND |<WRAP>  +| docker exec -it CONTAINERID COMMAND                                                                               | <WRAP>  You can find out the COMMAND available for CONTAINERID by doing //docker ps//.   <code> $ docker ps  CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS NAMES 625ad92a1f53        ubuntu:latest       "/bin/bash"         15 seconds ago      Up 14 seconds  $ docker exec -it 625ad92a1f53 "/bin/bash"  </code></WRAP>                                                                                   
-You can find out the COMMAND available for CONTAINERID by doing //docker ps//. +| docker inspect CONTAINER_NAME                                                                                     | Provide ALL data about the container.                                                                                                                                                                                                                                                                                                                                                                                                                                    
-<code> +| docker-machine ls                                                                                                 | list existing hosts                                                                                                                                                                                                                                                                                                                                                                                                                                                      
-$ docker ps +| docker-machine create --driver virtualbox HOSTNAME                                                                | create host                                                                                                                                                                                                                                                                                                                                                                                                                                                              
- +| docker-machine rm HOSTNAME                                                                                        | remove host                                                                                                                                                                                                                                                                                                                                                                                                                                                              
-CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS +| docker-machine restart HOSTNAME                                                                                   | restarts the host                                                                                                                                                                                                                                                                                                                                                                                                                                                        
-NAMES +| <code>start http://$(docker inspect -f "{{ .NetworkSettings.Networks.nat.IPAddress }}" grave_thompson):81</code>  | starts the container "grave_thompson", by requesting its IP by container name                                                                                                                                                                                                                                                                                                                                                                                            
-625ad92a1f53        ubuntu:latest       "/bin/bash"         15 seconds ago      Up 14 seconds +| docker attach CONTAINERNAME                                                                                       | Shows what is happening inside the container. You can even kill the process by CTRL+C                                                                                                                                                                                                                                                                                                                                                                                    
- +| docker commit jira skipidar/atlassian-jira:1.0                                                                    | store the docker container as a new image                                                                                                                                                                                                                                                                                                                                                                                                                                
-$ docker exec -it 625ad92a1f53 "/bin/bash" +| docker push skipidar/atlassian-jira                                                                               | save docker image to a repository "skipidar/atlassian-jira"                                                                                                                                                                                                                                                                                                                                                                                                              
-</code> +| docker exec <CONTAINER> <COMMAND>                                                                                 | <WRAP>  Executes a command in a container. E.g. to show which processes are running in container:    <code> PS D:\webserver> docker exec ubuntu2 ps -f UID         PID   PPID  C STIME TTY          TIME CMD root         51      0  0 15:09 ?        00:00:03 /usr/bin/python /usr/bin/ajenti-panel -d root        130      0  0 16:29 ?        00:00:00 nginx: master process /usr/sbin/nginx root        169      0  0 17:09 ?        00:00:00 ps -f  </code></WRAP>  
-</WRAP>+| docker run --restart=always jenkinsci/jenkins                                                                     | Makes the container automatically restart after host restart.                                                                                                                                                                                                                                                                                                                                                                                                            | 
-| docker inspect CONTAINER_NAME | Provide ALL data about the container. | +| docker top <CONTAINERID>                                                                                          | Lists the containers running processes                                                                                                                                                                                                                                                                                                                                                                                                                                   | 
-| docker-machine ls | list existing hosts| +| docker stats                                                                                                      | The resources consumed by docker                                                                                                                                                                                                                                                                                                                                                                                                                                         | 
-| docker-machine create --driver virtualbox HOSTNAME| create host| +| docker container logs -f <CONTAINERID>                                                                            | logs from inside the conatainer                                                                                                                                                                                                                                                                                                                                                                                                                                          |
-| docker-machine rm HOSTNAME| remove host| +
-| docker-machine restart HOSTNAME| restarts the host| +
-| <code>start http://$(docker inspect -f "{{ .NetworkSettings.Networks.nat.IPAddress }}" grave_thompson):81</code> | starts the container "grave_thompson", by requesting its IP by container name | +
-| docker attach CONTAINERNAME | Shows what is happening inside the container. You can even kill the process by CTRL+C | +
-| docker commit jira skipidar/atlassian-jira:1.0 | store the docker container as a new image | +
-| docker push skipidar/atlassian-jira | save docker image to a repository "skipidar/atlassian-jira"+
-| docker exec <CONTAINER> <COMMAND> | <WRAP>Executes a command in a container. E.g. to show which processes are running in container:  +
-<code> +
-PS D:\webserver> docker exec ubuntu2 ps -f +
-UID         PID   PPID  C STIME TTY          TIME CMD +
-root         51      0  0 15:09 ?        00:00:03 /usr/bin/python /usr/bin/ajenti-panel -d +
-root        130      0  0 16:29 ?        00:00:00 nginx: master process /usr/sbin/nginx +
-root        169      0  0 17:09 ?        00:00:00 ps -f +
-</code> +
- +
-</WRAP>+
-| docker run --restart=always jenkinsci/jenkins | Makes the container automatically restart after host restart.|+
  
  
Line 125: Line 108:
  
 ==== Setup on Windows ==== ==== Setup on Windows ====
 +
 +=== Using Docker Desktop ===
 +The command & 'C:\Program Files\Docker\Docker\DockerCli.exe' -SwitchDaemon is a Windows command that starts the Docker daemon on a Windows system and registers it as a system service.
 +
 +<code>
 +& 'C:\Program Files\Docker\Docker\DockerCli.exe' -SwitchDaemon
 +</code>
 +
 +=== Running containers
 +
 +Example 
 +<code>
 +docker run -it --gpus all -p 8080:8080 -v $HOME/.tabby:/data tabbyml/tabby serve --model StarCoder-1B
 + --device cuda --chat-model Qwen2-1.5B-Instruct
 +</code>
  
 === Using Windows native Hyper-V === === Using Windows native Hyper-V ===
Line 681: Line 679:
  
 So the IP Address of the docker host **172.17.42.1** is set as the default route and is accessible from your container. So the IP Address of the docker host **172.17.42.1** is set as the default route and is accessible from your container.
 +
 +
 +==== Docker Context ====
 +The files/folders, which are in the same folder, like the Dockerfile - are packaged to a tar.gz and sent to the target machine with the docker daemon.
 +
 +See https://docs.docker.com/engine/reference/commandline/build/#set-build-time-variables---build-arg
 +
 +You can explicitly create a tar.gz package and reference it during the build command. \\
 +The tar ball has a flat hierarchy here, but may have any structure. Only, when referencing the files inside - one should consider this structure.
 +
 +The DockerFile is referenced explicitely inside the tar.gz ball (**-f ./Dockerfile.run.txt**)
 +<code>
 +# create the context tar.gz
 +tar -C /vagrant -cvf /tmp/runappcontext.tar.gz de.webapp.spring.one-0.0.1-SNAPSHOT.jar Dockerfile.run.txt
 +
 +# build the container with an existing gzipped context
 +docker build  --no-cache -t runapp -f ./Dockerfile.run.txt - < /tmp/runappcontext.tar.gz
 +
 +# run the container
 +docker run --name runAppContainer -d -p 8080:8080 runapp 
 +</code>
 +
 +
 +==== Start bash in container as root ====
 +If you would like to connect to the container MYCONTAINERNAME as root,
 +<code>
 +docker exec -it --user root MYCONTAINERNAME bash
 +<code>
 +
 ====== ADOP ====== ====== ADOP ======
  
devops/docker.1515672987.txt.gz · Last modified: (external edit)