Skip to content

gautam-borkar/docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Docker

A handy guide to essential Docker commands for quick reference and efficient container management.


Docker Commands

Login to docker hub

docker login

Pulling an Image

docker pull <image-name>

Building an Image

docker build . -t <account-name>/<image-name>

Pushing an Image

docker push <account-name>/<image-name>

Running a Container

  • Basic run:

    docker run nginx
  • Run with a specific version:

    docker run <image-name>:<version>
  • Run with interactive input and prompt:

    docker run -it <image-name>
  • Run with a sleep command:

    docker run ubuntu sleep 5
  • Run with environment variable:

    docker run -e <env_name>:<env_value> <image_name>

    Docker networks

  • DeprecatedRun with link command

    docker run -d --link <hostname-in-application>:<container-name> <image-name>
  • Run with network command

    docker network create my-network
    docker run --network my-network --name container1 <image1>

Managing Ports and Volumes

  • Map host port to container port:
    docker run -p <docker-host-port>:<docker-container-port> <image-name>
  • Create and mount a volume
    • Volume mount
      docker volume create <volume_name>
      docker run --mount type=volume,source=<volume_name>,target=<location_inside_container> mysql
    • Bind mount
      docker run --mount type=bind,source=<folder_location_on_docker_host>,target=<location_inside_container> mysql
  • DeprecatedCreate and mount a volume
    • Volume mount
      docker volume create <volume-name>
      docker run -v <volume-name>:<location_inside_container>
    • Bind mount
      docker run -v <folder_location_on_docker_host>:<location_inside_container>

Container Management

  • Run in detached mode:
    docker run -d <image-name>
  • Get image layer details:
    docker history <image-name>
  • Attach to a running container:
    docker attach <container-id>
  • Execute a command in a running container:
    docker exec <container-id-or-name> <command>

Viewing and Inspecting

  • List all containers:
    docker ps -a
  • List all images:
    docker images
  • Inspect a container:
    docker inspect <container-name-or-id>
  • View container logs:
    docker logs <container-name-or-id>

Stopping and Removing

  • Stop a container:
    docker stop <container-id-or-name>
  • Remove a container:
    docker rm <container-id-or-name>
  • Remove an image:
    docker rmi <image-name>

Docker compose

Running docker compose

  • Run docker compose:
    docker-compose up

Docker registry

Running docker registry locally

  • Running docker registry locally
    docker run -d -p 5000:5000 --name registry registry:2

Push image to registry

  • Tag an image
    docker image tag <image-name> <tag-name>
  • Push image to registry:
    docker push <user-name>/<image-name>

Contributing

Feel free to contribute by adding more commands or improving existing ones! Open a pull request or file an issue for any suggestions.


License

This repository is licensed under the MIT License.


Happy Dockering! 🚢

About

Docker repository

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published