Table of contents
No headings in the article.
Pulling an image:
Syntax:
docker pull <image_name>:<tag>
Example:
docker pull ubuntu:latest
Building an image from a Dockerfile:
Syntax:
docker build -t <image_name> <path_to_dockerfile>
Example:
docker build -t myapp:1.0 .
Running a container:
Syntax:
docker run <options> <image_name>
Example:
docker run -d --name mycontainer myapp:1.0
Listing Docker images:
Syntax:
docker images
Example:
docker images
Removing an image:
Syntax:
docker rmi <image_name>
Example:
docker rmi myapp:1.0
Listing running containers:
Syntax:
docker ps
Example:
docker ps
Listing all containers (including stopped ones):
Syntax:
docker ps -a
Example:
docker ps -a
Starting a stopped container:
Syntax:
docker start <container_id>
Example:
docker start mycontainer
Stopping a running container:
Syntax:
docker stop <container_id>
Example:
docker stop mycontainer
Removing a container:
Syntax:
docker rm <container_id>
Example:
docker rm mycontainer
Running a command inside a container:
Syntax:
docker exec -it <container_id> <command>
Example:
docker exec -it mycontainer ls
Creating a Docker volume:
Syntax:
docker volume create <volume_name>
Example:
docker volume create myvolume
Listing Docker volumes:
Syntax:
docker volume ls
Example:
docker volume ls
Removing a Docker volume:
Syntax:
docker volume rm <volume_name>
Example:
docker volume rm myvolume
Creating a Docker network:
Syntax:
docker network create <network_name>
Example:
docker network create mynetwork
Listing Docker networks:
Syntax:
docker network ls
Example:
docker network ls
Removing a Docker network:
Syntax:
docker network rm <network_name>
Example:
docker network rm mynetwork
Running a container in a specific network:
Syntax:
docker run --network=<network_name> <image_name>
Example:
docker run --network=mynetwork myapp:1.0
Running Docker Compose:
Syntax:
docker-compose up
Example:
docker-compose up
Stopping and removing containers defined in a Docker Compose file:
Syntax:
docker-compose down
Example:
docker-compose down
Inspecting a Docker container:
Syntax:
docker inspect <container_id>
Example:
docker inspect mycontainer
Copying files between the host and a container:
Syntax:
docker cp <host_path> <container_id>:<container_path>
Example:
docker cp myfile.txt mycontainer:/app
Viewing the logs of a container:
Syntax:
docker logs <container_id>
Example:
docker logs mycontainer
Attaching to a running container's terminal:
Syntax:
docker attach <container_id>
Example:
docker attach mycontainer
Pausing and unpausing a running container:
Syntax:
docker pause <container_id>
anddocker unpause <container_id>
Example:
docker pause mycontainer
anddocker unpause mycontainer
Renaming a container:
Syntax:
docker rename <old_name> <new_name>
Example:
docker rename mycontainer newcontainer
Pushing an image to a Docker registry:
Syntax:
docker push <image_name>:<tag>
Example:
docker push myapp:1.0
Pruning unused Docker resources:
Syntax:
docker system prune
Example:
docker system prune
Inspecting a Docker volume:
Syntax:
docker volume inspect <volume_name>
Example:
docker volume inspect myvolume
Running a container in the background with a specific name:
Syntax:
docker run -d --name <container_name> <image_name>
Example:
docker run -d --name mycontainer myapp:1.0
These examples demonstrate the syntax and provide one-line commands for various Docker operations. Remember to replace <image_name>
, <tag>,
<container_id>
, <host_path>
,<old_name>
, <new_name>
, <volume_name>
, and <network_name>
with your own names as needed.
Thank you for reading. I hope you were able to understand and learn something new from my blog.
Happy Learning!
Please follow me on Hashnode and do connect with me on LinkedIn ArnavSingh