Useful commands for Docker

Installing docker-engine

For Redhat OS

### Start the services of docker $ systemctl restart docker It starts the docker server.

See all the images available in docker

$ docker images The default docker images will show all top level images, their repository and tags, and their size.

Load an image in docker

$ docker load -i ubuntu-14.04.tar

It loads an image or repository from a tar archive (even if compressed with gzip, bzip2, or xz) from a file or STDIN. It restores both images and tags.

Docker run reference

Run or start a new OS

$ docker run -it ubuntu:14.04

See all the running OSs

$ docker ps

$ docker ps -a

Come out from docker OS console

exit

From shell of docker OS, for coming out without exiting container

press ctrl + p + q

From terminal of base system, to run a command in docker OS

$ docker exec mycontainer ifconfig

Usually run docker using this command

$ docker run –dit ubuntu:14.04

Stop all running OSs

$ docker ps -q //shows id of every running OS 
$ docker stop  $(docker ps -q) 

Permanently remove a container

$ docker rm id

Permanently Remove all the stopped containers

$ docker rm $(docker ps -a -q)

Remove containers while running (forcefully)

$ docker rm -f $(docker ps -a -q)

Giving docker OS a name when starting

Copy a file in container

$ docker cp /root/form.txt myconatiner:/ This command will copy a file form.txt from the base system to the specified container.

Download docker images

docker hub - All the available docker images can be downloaded from this URL.

Check different versions of OS that are available

$ docker search ubuntu //search
$ docker pull ubuntu:17.10 //downlaod required version 

Docker Storage

Basic Storage types

  1. Empheral disk (temporary) – OS removal will remove data (like windows C drive)
  2. Persistent disk (permanent) - OS removal will not erase data (like windows D drive)

Docker volume manager

Docker by default takes space from / drive of host system to store data. Overall / drive amount of storage docker can use.

Give separate space to a docker container

Attaching dvd to a container

$ docker run –it –v /run/media/root/RHEL-7.3\ Server.. centos This command will attach a RHEL to the container.

Copy content from a folder of base system to /data in docker centos

$ docker run –it -v /folder_name:/data centos