Skip to content

Instantly share code, notes, and snippets.

@Khnaz35
Created October 27, 2023 14:24
Show Gist options
  • Save Khnaz35/43df20086a06ae70933d46d985196a23 to your computer and use it in GitHub Desktop.
Save Khnaz35/43df20086a06ae70933d46d985196a23 to your computer and use it in GitHub Desktop.

Docker Command Basics

  1. docker run: Used to create and start a container.

    • Example: docker run hello-world runs a container from the "hello-world" image.
    • Example: docker run -it ubuntu bash runs an Ubuntu container and opens a bash shell.
  2. docker ps: Lists running containers.

    • Example: docker ps shows all currently running containers.
  3. docker ps -a: Lists all containers, both running and stopped.

    • Example: docker ps -a
  4. docker images: Shows a list of all images on the local system.

    • Example: docker images
  5. docker pull: Pulls an image from a Docker registry.

    • Example: docker pull nginx pulls the Nginx image from Docker Hub.
  6. docker build: Builds a Docker image from a Dockerfile.

    • Example: docker build -t my-image . builds an image with the tag "my-image" from the current directory.
  7. docker exec: Runs a command in a running container.

    • Example: docker exec -it my-container bash opens a bash shell inside "my-container".
  8. docker stop: Stops a running container.

    • Example: docker stop my-container
  9. docker start: Starts a stopped container.

    • Example: docker start my-container
  10. docker rm: Removes a container.

    • Example: docker rm my-container
  11. docker rmi: Removes an image.

    • Example: docker rmi my-image
  12. docker logs: Shows logs for a container.

    • Example: docker logs my-container
  13. docker network: Manages networks.

    • Example: docker network ls lists all Docker networks.
  14. docker volume: Manages volumes.

    • Example: docker volume ls lists all Docker volumes.
  15. docker-compose: Used to define and run multi-container Docker applications.

    • Example: docker-compose up starts the services defined in docker-compose.yml.
    • Example: docker-compose down stops the services started by docker-compose up.

Conclusion

These commands cover the basics of interacting with Docker, including managing containers, images, networks, and volumes. For more detailed information and examples, refer to the official Docker documentation.

Docker Installation Guide for MacOS and Windows

This guide provides general instructions on how to install Docker on MacOS and Windows systems.

MacOS

Prerequisites

  • An Intel-based Mac or a Mac with Apple silicon
  • MacOS 10.14 (Mojave) or newer
  • An Apple ID

Installation Steps

  1. Download Docker Desktop: Visit the Docker official website and download Docker Desktop for Mac.

  2. Install Docker Desktop:

    • Open the downloaded Docker.dmg file.
    • Drag and drop the Docker icon to the Applications folder to start the installation.
    • You might need to provide your Mac's username and password to proceed.
  3. Verify Installation:

    • Open Docker Desktop from the Applications folder or using Spotlight Search.
    • Wait for Docker Desktop to finish starting up. You'll see the Docker icon in the Mac status bar when it's ready.
  4. Run the Docker Hello-World Image (Optional):

    • Open Terminal.
    • Run docker run hello-world.
    • If Docker is installed correctly, you will see a message indicating that your Docker installation is working.

Windows

Prerequisites

  • Windows 10 64-bit: Home or Pro version 2004 or higher, or Enterprise or Education version 1909 or higher
  • Windows Subsystem for Linux 2 (WSL 2)
  • Virtualization enabled in BIOS
  • A Microsoft account

Installation Steps

  1. Enable WSL 2:

    • Open PowerShell as Administrator.
    • Run wsl --install to enable WSL 2.
  2. Download Docker Desktop: Visit the Docker official website and download Docker Desktop for Windows.

  3. Install Docker Desktop:

    • Open the downloaded Docker Desktop Installer.exe file.
    • Follow the on-screen instructions to complete the installation.
    • Restart your computer if prompted.
  4. Verify Installation:

    • Open Docker Desktop from the Start menu.
    • Wait for Docker Desktop to finish starting up. You'll see the Docker icon in the Windows system tray when it's ready.
  5. Run the Docker Hello-World Image (Optional):

    • Open PowerShell or Command Prompt.
    • Run docker run hello-world.
    • If Docker is installed correctly, you will see a message indicating that your Docker installation is working.

Conclusion

You have now installed Docker on your MacOS or Windows system and verified that it is working correctly. You can start using Docker to create containers, run applications, and more. Ensure to check the official Docker documentation for more detailed instructions and best practices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment