Skip to content

Latest commit

 

History

History
148 lines (101 loc) · 3.67 KB

File metadata and controls

148 lines (101 loc) · 3.67 KB

Docker

  • Author: Pedric Kng
  • Updated: 19 Feb 2020

DevOps Tooling


Docker commands

  • Executing a command
sudo docker exec -it <container name> <command>  
e,g., sudo docker exec -it jenkins /bin/bash
  • Executing a command as root
docker exec --user="root" -it bamboo-server /bin/bash
  • List docker volumes
 docker volume ls
  • Inspect docker volume
 docker volume inspect <volume_name>
  • List container
 docker container ls
  • Inspect container
 docker container inspect <container_name>
  • Run container with attached volume
 docker run -it -v ~/container-data:/data mcr.microsoft.com/powershell /bin/bash
  • Update container
 docker update --restart=no <container_name>
  • Run container with name
 docker run -d --name <container name> <container repo:tag>
  • Run container with cleanup
 docker run --rm -it <container repo:tag>
  • Build container image
 docker build -t <username/container:tag>
  • Run container interactively, override entrypoint
sudo docker run -it --entrypoint /bin/bash [docker_image]

Dockerhub

  • Pushing image to Dockerhub registry
# tag
docker image tag <local_image>:<tag> <repo>/<remote_image>:<tag>
docker image push <repo>/<remote_image>:<tag>

HyperV nested virtualization

!!! Note that VMName containing special characters are not accepted, and features e.g., dynamic memory is not supported for nested virtualized machine. 
  • Enable nested virtualization

    # Get list of vm, and their name
    Get-VM
    
    # Set nested virtualization for VM
    Set-VMProcessor <VMName> -ExposeVirtualizationExtensions $true
    

Common Troubleshooting

  • Permission denied connecting to the Docker Daemon socket

    # Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.39/images/create?fromImage=webgoat%2Fwebgoat-8.0&tag=v8.0.0.M21: dial unix /var/run/docker.sock: connect: permission denied
    
    sudo chmod 666 /var/run/docker.sock
  • Mounted volume not readable or writeable

    If the mounted volume is not readable/writeable in the container, it is due to the user in the container having different userid:groupid than the user on the host.

    To get around this is to start the container without the (problematic) volume mapping, then run bash on the container:

    docker run -p 8080:8080 -p 50000:50000 -it jenkins bin/bash
    
    id
    
    # Once inside the container's shell run the id command and you'll get results like:
    #uid=1000(jenkins) gid=1000(jenkins) groups=1000(jenkins)
    
    #Exit the container, go to the folder you are trying to map and run:
    chown -R 1000:1000 .
    

    With the permissions now matching, you should be able to run the original docker command with the volume mapping.

  • Jenkins pipeline Job can't find script due to temp path @tmp....

    Issue is likely due to Jenkins host symlinks bin/sh to dash; not bash

    Adding "/bin/sh" to the "Shell Executable" option under "Manage Jenkins -> Configure System" will help to resolve it.

References

host volume not writable [1]