Docker Basic Commands
https://www.cloudmantra.net/blog/docker-installation-basic-commands/

Docker Basic Commands

In the realm of modern software development, efficiency and consistency are paramount. Docker, a powerful tool in the world of containerization, has revolutionized how developers build, ship, and run applications. Understanding Docker basic commands is akin to mastering the sails of a ship navigating through the vast ocean of containerized environments. In this blog post, we embark on a journey to explore these fundamental Docker commands that every developer should know.

What is Docker?

Before diving into Docker commands, let's briefly recap what Docker is. Docker is a platform designed to make it easier to create, deploy, and run applications by using containers. Containers allow developers to package an application with all of its dependencies into a standardized unit for software development, providing isolation, portability, and consistency across environments.

Getting Started with Docker

To embark on our Docker journey, you'll need to have Docker installed on your system. Once Docker is up and running, open your terminal or command prompt and let's begin.

Docker Basic Commands

1. docker version

This command displays the Docker version installed on your system, along with the version of the Docker client and server.

docker version        

2. docker info

Similar to docker version, docker info provides more detailed information about your Docker installation, including the number of containers and images present.

docker info        

3. docker run

The docker run command is used to create and start a container based on a Docker image.

docker run [OPTIONS] IMAGE [COMMAND] [ARG...]        

For example:

docker run -it ubuntu /bin/bash        

This command runs an Ubuntu container interactively and opens a bash shell.

4. docker pull

To download a Docker image from a registry, you can use the docker pull command.

docker pull IMAGE_NAME        

For instance:

docker pull nginx        

This command fetches the latest Nginx image from the Docker Hub registry.

5. docker ps

The docker ps command lists all running containers.

docker ps [OPTIONS]        

To view all containers, including those that have exited, use the -a option:

docker ps -a        

6. docker stop and docker start

To stop or start a container, respectively, you can use these commands.

docker stop CONTAINER_ID docker start CONTAINER_ID        

7. docker rm and docker rmi

To remove containers and images, you can use docker rm and docker rmi, respectively.

docker rm CONTAINER_ID docker rmi IMAGE_ID        


Let's delve deeper into Docker with more commands beyond the basics:

1. Docker Container Management

a. docker exec

This command allows you to execute commands inside a running container.

docker exec [OPTIONS] CONTAINER COMMAND [ARG...]        

For example, to execute a bash shell inside a running container:

docker exec -it CONTAINER_ID /bin/bash        

b. docker logs

To view the logs of a specific container, you can use the docker logs command.

docker logs [OPTIONS] CONTAINER        

For example:

docker logs CONTAINER_ID        

c. docker cp

To copy files or directories between a container and the local filesystem, you can use docker cp.

docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH docker cp [OPTIONS] SRC_PATH CONTAINER:DEST_PATH        

For instance, to copy a file from a container to the local filesystem:

docker cp CONTAINER_ID:/path/to/file.txt /local/path        

2. Docker Image Management

a. docker images

To list all Docker images on your system, you can use the docker images command.

docker images [OPTIONS]        

b. docker tag

The docker tag command is used to tag an image with a specific tag.

docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]        

For example:

docker tag my_image:latest my_repo/my_image:latest        

c. docker build

To build a Docker image from a Dockerfile, you can use the docker build command.

docker build [OPTIONS] PATH | URL | -        

For instance:

docker build -t my_image:latest .        

3. Docker Network Management

a. docker network ls

This command lists all Docker networks.

docker network ls        

b. docker network inspect

To inspect a specific Docker network, you can use docker network inspect.

docker network inspect NETWORK_ID        

c. docker network create

To create a new Docker network, you can use the docker network create command.

docker network create [OPTIONS] NETWORK_NAME        

For example:

docker network create my_network        

4. Docker Compose

a. docker-compose up and docker-compose down

These commands are used to start and stop Docker Compose services defined in a docker-compose.yml file.

docker-compose up docker-compose down        

b. docker-compose ps

To list all Docker Compose services along with their status, you can use docker-compose ps.

docker-compose ps        


Mastering Docker basic commands is essential for navigating the containerized world of modern software development. With these commands at your disposal, you can efficiently manage Docker containers and images, streamline your development workflow, and sail smoothly through the seas of containerization.

As you continue your Docker journey, remember to explore more advanced Docker features and best practices to further enhance your development experience. Bon voyage!


Author

Nadir Riyani is an accomplished and visionary Engineering Manager with a strong background in leading high-performing engineering teams. With a passion for technology and a deep understanding of software development principles, Nadir has a proven track record of delivering innovative solutions and driving engineering excellence. He possesses a comprehensive understanding of software engineering methodologies, including Agile and DevOps, and has a keen ability to align engineering practices with business objectives. Reach out to him at [email protected] for more information.


要查看或添加评论,请登录

Nadir R.的更多文章

  • CodeWhisperer: Amazon’s AI-Powered Coding Assistant

    CodeWhisperer: Amazon’s AI-Powered Coding Assistant

    The world of software development is rapidly evolving, and one of the most exciting innovations in recent years is the…

  • Axe by Deque: Tool for Web Accessibility Testing

    Axe by Deque: Tool for Web Accessibility Testing

    Web accessibility is crucial in ensuring that all users, regardless of their abilities, can access and interact with…

  • Structure101:Tool for Managing Software Architecture

    Structure101:Tool for Managing Software Architecture

    In the world of software development, maintaining a clean and efficient architecture is critical to the long-term…

  • Risks, Assumptions, Issues, and Dependencies in Project (RAID)

    Risks, Assumptions, Issues, and Dependencies in Project (RAID)

    RAID is an acronym that stands for Risks, Assumptions, Issues, and Dependencies. It is a project management tool used…

  • RAG: Red, Amber, Green

    RAG: Red, Amber, Green

    RAG stands for Red, Amber, Green, and it is a color-coded system commonly used to represent the status or performance…

  • SQLite Vs MongoDB

    SQLite Vs MongoDB

    SQLite and MongoDB are both popular databases, but they differ significantly in their structure, use cases, and…

  • Microservices architecture best practices

    Microservices architecture best practices

    Microservices architecture is an approach to building software where a large application is broken down into smaller…

  • Depcheck: Optimize Your Node.js Project

    Depcheck: Optimize Your Node.js Project

    When it comes to managing dependencies in a Node.js project, one common issue developers face is dealing with unused or…

  • Color Contrast Analyzer

    Color Contrast Analyzer

    In the world of web design and accessibility, one of the most crucial elements that often gets overlooked is color…

  • DevOps Research and Assessment(DORA)

    DevOps Research and Assessment(DORA)

    In today's fast-paced software development world, organizations are constantly looking for ways to optimize their…

社区洞察

其他会员也浏览了