Basic Commands

Here are couple of basic commands for using Docker.

Docker containers are immutable.

Pull a docker image from hub

docker pull busybox:latest

Run Docker image to execute an operation

We can run docker image, execute an operation and kill the docker container. --rm flag will reference to the Docker container when it is finished.

The following command will start docker container, execute echo and exit.

docker run --rm busybox:latest /bin/echo "Hello World"

If we don't use --rm flag, the container is not removed and we can see it when we run docker ps -a. Then we need to remove it manually.

Run Docker image

We can run docker image and connect to it. -it flag says Docker to run the container in interactive mode.

docker run -it --rm busybox:latest

Manage Docker images

We list all the docker images.

Then we can remove Docker image.

Running Docker containers

First, we can list all running containers. -a flag will make sure we see all the containers.

We can remove running Docker container.

Last updated

Was this helpful?