Useful Docker Command List with Examples
Docker is an emerging technology used mainly by developers and system administrators. I provides the flexibility to run different environments with little system overload and resources. In this tutorial we will learn basic but useful Docker commands with examples.
List Docker Commands
We generally need to list provided commands to remember or learn. We can list existing Docker commands by running
docker command like below.
run – Run New Container
Now we will start with a basic command which will start a container in daemon mode. The default behavior of Docker is running given container and stopping it. We can run in daemon mode with
run command like below.
$ sudo docker run -t -i ubuntu bash
start – Start Stopped Container
start command will start all ready created but stopped container. In this example we will start container named
$ sudo docker start test
stop – Stop Running Container
stop command will stop all ready created but started container. In this example we will stop container named
$ sudo docker stop test
pull – Pull A Container Image
Docker images provide required files, libraries and system files. We can create them by building Docker image or pulling from registers. Docker hub is open source register used by default. We can get an image from Docker Hub with
pull command. In this example we will pull
ubuntu image like below.
$ sudo docker pull ubuntu
build – Build Docker Image From Docker File
Docker images generally pulled from registry. But we can also create Docker image with defined configuration. We create some Docker File which provides build information like which based image will be used, which users, files will be create or packages will be installed. We can create image like below. run
build command while current working directory is Docker file path.
$ sudo docker build .
exec – Run Command In Existing Container
exec is very popular command because it runs commands in all ready running Container . We just provide the command we want to execute in given container. In this example we will run
whoami command in the container. We will provide the container id and the command.
$ sudo docker exec a59e88993206 whoami
search – Search Docker Images In Docker Hub
While creating Container environment we generally need a lot of prebuilt Container images. We can search for them in Docker Hub with
search command like below.
$ sudo docker search suricata
commit – Create New Image From Running Container
Another popular scenario in Docker usage is changing and putting data in some containers and saving this containers for future use without losing data. As we know changes made in container will lost after stop. So we will commit them by using their container ID and the new name we want to use.
$ sudo docker commit a59e88993206 mynewcontainer