Docker Essentials: A Guide to Key Commands

Docker Essentials: A Guide to Key Commands

Β·

2 min read

Welcome to "A Guide to key commands in Docker"! In this post, we're going to simplify some key concepts and commands that you need to know to start working with Docker, one of the most popular containerization platforms.


What is Docker? 🐳
Docker is a platform that enables developers to package applications into containers standardized executable components combining application source code with the operating system (OS) libraries and dependencies required to run that code in any environment.


Basic Docker Commands: πŸ’‘

  1. Docker Run:

    • docker run <image_name>: This is the command you'll use to start a new container from an image.
  2. Overriding Default Commands:

    • You can override the default command set in the Docker image by appending a new command after the image name:

      • docker run <image_name> <command>
  3. Listing Running Containers:

    • To see the currently running containers, use docker ps. For a list that includes stopped containers, add the --all flag: docker ps --all.
  4. Container Lifecycle:

    • docker create <image_name> followed by docker start <container_id> can be used as a two-step alternative to docker run.
  5. Removing Containers:

    • docker system prune: This command removes all stopped containers and other unused objects like dangling images and unused networks.

Container Interaction: 🀝

  1. Stopping Containers:

    • docker stop <container_id>: Gracefully stops a running container.
  2. Executing Commands in Running Containers:

    • docker exec -it <container_id> <command>: Lets you run additional commands in running containers.
  3. The -it Flag:

    • This flag is short for --interactive + --tty. It allows you to interact with the container via a terminal interface.

Advanced Docker Commands: πŸš€

  1. Docker Logs:

    • To retrieve the logs of a container, use docker logs <container_id>.
  2. Docker Kill:

    • Use docker kill <container_id> to force stop a running container.

Conclusion:

There you have it, a starter on some of the basic yet crucial Docker commands and their purpose. Remember, practice makes perfect.

The more you use these commands, the more comfortable you'll become with the Docker environment.

Stay tuned for more blogs on Docker and containerization! 🚒

Β