Important commands while working with docker

Shobhit Srivastava
2 min readMay 25, 2021
Pexels image from Chelsey Horne

Following are the docker commands for building the docker image, creating container out of it and finally pushing it to the dockerhub.

Please follow the following commands for executing the set of tasks as desribed below:

1. Command to list down all the image

$ docker images

2. Command to list down all the running docker images(called docker container)

$ docker ps

3. Command to build container out of images using image name and docker file

docker build -t <imagename> .

4. Command to run the docker image by port configuration

$ docker run -d -p p1:p2 <imagename>

5. Command to get inside the running docker container

$ docker exec -it <containerid> bash

6. While pushing the docker image to dockerhub repo we need to make some changes to our image name

docker tag <imagename> reponame/<imagename>[:tag]

7. Below commands forward the traffic form the local host to the pod using the ports of both the services

kubectl port-forward pod/mongo-db-r3pl1ka3 8080:5762

8. Command to run the ubuntu image pulled from dockerhub

docker run -it -d ubuntu

9. Command to open bash terminal for getting access to running container

docker container exec -it 143de65a8029 bash

10. Creating a docker volumes

docker volume create <volume name>

This command create a folder in you pc where docker is installed and further you can mount this volume with any docker container.

There are lot of commands as such to follow with the coming blogs. So please stay tune.

--

--

Shobhit Srivastava

Software Developer | My areas of interest are: Software Development, OpenSource, Startups, Innovation