Table of contents
No headings in the article.
Docker commands are a set of instructions that allow you to interact with Docker containers and images. They can be used to create, start, stop, and manage containers, as well as to inspect and manage images.
Here are some of the most common Docker commands:
docker run: This command creates and starts a new container from an image.
docker ps: This command lists all of the running containers.
docker stop: This command stops a running container.
docker kill: This command forcefully stops a running container.
docker inspect: This command displays detailed information about a container.
docker images: This command lists all of the images that are available locally.
docker pull: This command downloads an image from a remote repository.
docker push: This command uploads an image to a remote repository.
docker build: This command creates a new image from a Dockerfile.
Docker commands can be used to automate many tasks related to container management. For example, you can use a shell script to create a new container, start it, and then run a command inside of it. You can also use Docker commands to create a pipeline that automatically builds, tests, and deploys your application.
Docker commands are a powerful tool that can help you to manage your containers and images more effectively. By learning how to use these commands, you can improve your productivity and make it easier to build, deploy, and manage your applications.
Here are some additional details about some of the most common Docker commands:
- docker run: The
docker run
command takes a number of arguments, including the image name, the command to run inside the container, and any environment variables that you want to set. For example, the following command creates a new container from thenginx
image and starts thenginx
service inside of it:
Code snippet
docker run -d nginx
- docker ps: The
docker ps
command lists all of the running containers. By default, it displays the container ID, the image name, the status, and the command that was run when the container was started. You can also use the-a
flag to list all of the containers, including those that are stopped.
Code snippet
docker ps
- docker stop: The
docker stop
command stops a running container. The container will be stopped gracefully, and any data that was written to disk will be preserved.
Code snippet
docker stop <container_id>
- docker kill: The
docker kill
command forcefully stops a running container. Any data that was written to disk will be lost.
Code snippet
docker kill <container_id>
- docker inspect: The
docker inspect
command displays detailed information about a container. This information includes the container ID, the image name, the environment variables, the network settings, and the filesystem.
Code snippet
docker inspect <container_id>
- docker images: The
docker images
command lists all of the images that are available locally. By default, it displays the image ID, the image name, the size, and the date that the image was created. You can also use the-a
flag to list all of the images, including those that are not tagged.
Code snippet
docker images
- docker pull: The
docker pull
command downloads an image from a remote repository. The remote repository can be Docker Hub, or it can be a private repository that you have access to.
Code snippet
docker pull <image_name>
- docker push: The
docker push
command uploads an image to a remote repository. The remote repository can be Docker Hub, or it can be a private repository that you have access to.
Code snippet
docker push <image_name>
- docker build: The
docker build
command creates a new image from a Dockerfile. The Dockerfile is a text file that contains instructions for building the image.
Code snippet
docker build -t <image_name> .
I hope this helps!