Commands cheatsheet

Working with Docker registries:

A registry is a centralized repository for sharing docker images with others.

  • docker login: Connects to a docker registry with an username and a password. You can be logged in to multiple Docker registries at the same time.

    Examples:

      docker login [REGISTRY ADDRESS]
      docker login registry.thingsandcode.com
    
      docker login [REGISTRY ADDRESS] -u [USERNAME] - p [PASSWORD]
      docker login registry.thingsandcode.com -u=Branyac -p=FakePassw0rd
    
  • docker logout: Disconnects from a docker registry.

    Examples:

      docker logout [REGISTRY ADDRESS]
      docker logout registry.thingsandcode.com
    
  • docker pull: Downloads the specified tag version of an image from a remote Docker registry. The default registry is DockerHub. Take in mind that this command may fail if the name of the image is incorrect or the desired tag is not available for the architecture of the computer that has docker.

    Examples:

      docker pull [IMAGE]:[TAG]
      docker pull pihole:latest
    
      docker pull [ADDRESS OF REGISTRY]/[IMAGE]:[TAG]
      docker pull mcr.microsoft.com/oss/nginx/nginx:1.15.5-alpine
    
  • docker push: Uploads a local docker image to a remote registry. The default registry is DockerHub.

    Examples:

      docker push [IMAGE]:[TAG]
      docker push thingsandcode-web:20220830
    
      docker push [ADDRESS OF REGISTRY]/[IMAGE]:[TAG]
      docker push registry.thingsandcode.com/thingsandcode-web:20220830
    

Working with docker images

Docker images contain the required dependencies (For example: files, environment settings, operating system, etc.) to execute a container.

  • docker build: Creates a new docker image. It pulls a context Docker image and applies the steps of a dockerfile to build an output image.

    Example:

      docker build .
    
  • docker tag: Changes the tag of a local docker image.

    Example:

      docker tag [ORIGIN IMAGE]:[ORIGIN TAG] [OUTPUT IMAGE]:[OUTPUT TAG]
      docker tag thingsandcode-web:20220830-test thingsandcode-web:20220830-pro
    
      docker tag [ADDRESS OF ORIGIN REGISTRY]/[ORIGIN IMAGE]:[ORIGIN TAG] [ADDRESS OF OUTPUT REGISTRY]/[OUTPUT IMAGE]:[OUTPUT TAG]
      docker tag registry-testing.thingsandcode.com/thingsandcode-web:20220830-test registry-production.thingsandcode.com/thingsandcode-web:20220830-pro
    
  • docker save: Exports local Docker image to a tar file. Use it to backup local docker images or share it without uploading to a Docker registry.

    Example:

      docker save [IMAGE] > [OUTPUT FILENAME]
      docker save thingsandcode.com/thingsandcode-web:20220830-pro > /tmp/thingsandcode-web_20220830-pro.tar
    
  • docker load: Imports Docker image from a tar file to localhost.

    Example:

      docker load --input [INPUT FILENAME]
      docker load --input /tmp/thingsandcode-web_20220830-pro.tar
    

Remove unused resources

These commands will help you to free space in disk.

  • docker image prune: Removes local Docker images that are not being use by any container.

    Example:

      docker image prune
    
      docker image prune -af # Removes images without asking for confirmation
    

Author

Sergio Monedero

I am excited to share my knowledge and insights on programming and devops through this personal website. I am a lifelong learner with a passion for technology, and I enjoy staying up-to-date on the latest industry trends.

Keep in touch with Me: SergioCoder@LinkedIn | Branyac@Github