Site icon Learning & Doing

Docker command

#Cek info versi docker

docker info

#Mengunduh images dari Docker hub

docker pull [image name]

#Menghapus image dalam docker

docker rmi [image ID]

#Melihat daftar image

docker images

#Membuat container baru

docker run [image name] [command to run]

#Menyetop container

docker stop [container ID]

#Start container

docker start [container ID]

#Melihat daftar kontainer

docker ps -a

#Menghapus kontainer yang ada

docker rm [container ID]

#Melakukan commit perubahan pada images

docker commit [container ID] [imag

Let’s check Docker version installed on the machine.

# docker -v
# docker version
Docker version 1.5.0, build a8a31ef/1.5.0

##info
# docker info

##The search command allows you to search for Docker images in Docker registry, lets search images related to WordPress.

# docker search wordpress

##Here is the tutorial on how to push your Docker images to Docker Hub.

# docker pull centos

##list the available Docker images on the system.

# docker images

##You can remove downloaded images using rmi command; below command removes Ubuntu image from the local system.

# docker rmi ubuntu

##The following command is widely used to create containers, uses the “centos” docker image to create a container.

# docker run -dit --name docker-centos --hostname="centos" centos /bin/bash

-d = Running a docker container in the background

-i = Running a docker container in interactive mode.

-t = Allocates tty terminal wich is required to attach to the container.

–name = Name of a docker container

–hostname = Set a host to container

##Check the running containers using ps command.

# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
1f99133e0387        centos:latest       "/bin/bash"         About a minute ago   Up About a minute                       docker-centos

##The attach command lets you to attach to running container (docker-centos), you can see the hostname is set to centos, also run some test commands like “df -h” to see the mount points details.

[root@server ~]# docker attach docker-centos

[root@centos /]# df -h
Filesystem                                                                                     Size  Used Avail Use% Mounted on
/dev/mapper/docker-253:1-369-14d43fd37613411218528b599dd1c39a7b19ae2041a26a2cb170f52e8bc591e8  9.8G  254M  9.0G   3% /
tmpfs                                                                                          490M     0  490M   0% /dev
shm                                                                                             64M     0   64M   0% /dev/shm
/dev/mapper/fedora--server-root                                                                 50G  1.9G   45G   4% /etc/hosts
tmpfs                                                                                          490M     0  490M   0% /proc/kcore

##The docker run command allows you to run a command in a container. For example, let’s get an information of mount points within a container.

–rm = removes the container when the process exits.

# docker run --rm  centos /usr/bin/df -h

Filesystem                                                                                     Size  Used Avail Use% Mounted on
/dev/mapper/docker-253:1-369-8c3daee9969e4096047fa7b6802cccefe2b78ac176347d5b0feb9d4df4156c6d  9.8G  254M  9.0G   3% /
tmpfs                                                                                          490M     0  490M   0% /dev
shm                                                                                             64M     0   64M   0% /dev/shm
/dev/mapper/fedora--server-root                                                                 50G  1.9G   45G   4% /etc/hosts
tmpfs                                                                                          490M     0  490M   0% /proc/kcore

##The top command shows running process and their details.

# docker top docker-centos

UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
root                3442                2121                0                   21:44               pts/2               00:00:00            /bin/bash

##The stats command does live stream of resource usage statistics, the output of this command will look like a normal top command.

# docker stats docker-centos

##The cp command will help you to copy files/folders from containers to a host system; the following command will copy “to be copied” to /root of a host machine.

# docker cp docker-centos:/tobecopied /root/

##The kill command sends the SIGTERM to kill a running container.

# docker kill docker-centos

##The start command lets you start a stopped container; let’s start the docker-centos.

# docker start docker-centos

##The restart command helps you to restart a container.

# docker restart docker-centos

##The stop command lets you stop a container gracefully

# docker stop docker-centos

##The rename command allows you to change the name of the container, following command rename the docker-centos to MyCentOS.

# docker rename docker-centos MyCentOS

##The rm command will allow you to remove a container.

# docker rm MyCentOS

Exit mobile version