Docker basics

Docker has established itself as a key player in the IT world with many companies adopting it in the production environment. I will go through some docker commands that will be handy while using the service.

$docker

Once docker is successfully installed and setup, this command will list available options and command you can use in combination to interact with docker engine
$docker version

This command lists installed version of client and server docker engine in the system
$docker info

This command shows various information related to the docker installation
$docker login

Login into docker registry to push/pull images
$docker image ls

List all the downloaded images
$docker ps

List running containers

$docker ps -a

List all the containers including stopped ones

$docker ps -l

List last exited container
$docker run

Start a container.
E.g.
$docker run -it --rm -p <hostport>:<containerport> --name <containername> <imagename>:<tag> <shell> -c <command 1;command 2>

Above command starts a container with provided name using image with specified tag. It also starts given shell after the container starts and runs given commands. The --rm flag deletes the container once it is exited. The -p flag maps host port to the container port. If the host port is not given, docker uses a random port.
$docker attach

Connect to a running container
Usage:
$docker attach <containerID/Name>
$docker exec

Run a new command in a running container
$docker logs

View logs of a container
$docker kill

Kill one or more container
$docker rm

Remove one or more containers
$docker network

Manage networks used by containers

$docker network create

Create a new network

$docker network connect

Connect a container to a network
Usage:
$docker network connect <network_name> <container_name>

$docker network disconnect

Disconnect a network from a container

$docker network ls

List all networks

$docker network prune

Delete all unused networks

$docker network rm

Remove one or more networks
$docker commit

Create a new image from a container
Usage:
$docker commit <container ID/Name> <ImageName>:<Tag> 

If the tag is not provided, docker uses latest as default tag.
$docker tag 

Create a new image or update the tag of an existing image
$docker pull

Pull an image from docker registry
$docker push

Push an image to docker registry
$docker rmi

Remove and/or untag image

For more detail information, visit docker’s official documentation page.

Leave a Reply

Your email address will not be published.