Basics of Docker commands

Submitted on Wed, 04/24/2024 - 07:54

Tags

docker --help

Displays help text on all the Docker commands

docker COMMAND --help

Displays help text on a particular Docker command. For example,

docker pull --help

Displays help text on Docker pull command

docker version

Displays version information on Docker client and server

docker pull owncloud

Pulls the docker image named owncloud from Docker registry at hub.docker.com. An image can have multiple versions. Since no version was mentioned, this command pulls the latest version of owncloud image.

docker pull owncloud:8.1

Pulls the 8.1 version of owncloud image from Docker registry.

docker images

Displays information on Docker images available locally on the machine.

docker save -o nextcloud.tar nextcloud

Creates a compressed tar file from nextcloud image.

docker load -i nextcloud.tar

Creates a Docker image from the compressed tar file.

docker volume create drupalweb

Creates a Docker volume named drupalweb.

docker volume ls

Displays information on Docker volumes.

docker network create --subnet 10.10.10.0/29 drupalnet

Creates a Docker network named drupalnet with Network ID as 10.10.10.0/29. 

docker network ls

Displays information on Docker networks.

docker run -dit -p 5000:80 -v nextvol:/var/www/html --name nextsrv nextcloud

Runs a Docker container named nextsrv from nextcloud image with container's 80 port mapped to host OS's 5000 port and the folder /var/www/html in the container mapped to a volume named nextvol. If the nextcloud image is not available locally, it will pull the image from Docker registry. The container shall run in the background mode as suggested by -dit argument.

docker run -dit -v nextdbvol:/var/lib/mysql -e MARIADB_ROOT_PASSWORD=nepal --name nextdbsrv mariadb

Runs a Docker container named nextdbsrv from mariadb image with the folder /var/lib/mysql mapped to a volume named nextdbvol and an environment variable named MARIADB_ROOT_PASSWORD set as nepal. If the mariadb image is not available locally, it will pull the image from Docker registry. The container shall run in the background mode.

docker exec -it nextdbsrv bash

Enters into a docker container named nextdbsrv using bash as terminal.

docker inspect nextdbsrv

Displays all the low level information on the Docker object. In this case a container named nextdbsrv. This command can be applied to images, volumes and networks as well.

docker logs nextdbsrv

Displays logs related to a container named nextdbsrv. Useful for diagnosis purposes.

docker stop nextdbsrv

Stops a running container named nextdbsrv

docker start nextdbsrv

Starts a stopped container named nextdbsrv.

docker restart nextdbsrv

Restarts a container named nextdbsrv.

docker rm nextdbsrv

Removes a container named nextdbsrv. The container must be stopped earlier.

docker rm -f nextdbsrv

Forcefully removes a container named nextdbsrv. The container may be in running state or stopped state.

docker rmi nextcloud

Removes an image named nextcloud. The image should not be in use by any container. If any container has been created using this image, this container has to be deleted first.

docker ps

Displays running containers.

docker ps -a

Displays all the containers, both running and stopped.

docker port nextdbsrv

Displays port mapping details for a container named nextdbsrv.