Author Kamal Kumar on September 01, 2020 26  Views

Docker Basics ~ Running our first container

In this article, we will understand basic commands of Docker, running our first container, pubilsh port on host machine, deleting containers, listing containers, etc.
What we will cover in this article -

Basic commands of Docker

docker version

docker info

 

Difference between Image and Container

 

The image is the in-rest version of the container which has all the configurations we have done.

The container is running version of that image.

Starting up our first container

docker container run --publish 80:80 nginx

Starting up a container in the background

docker container run --publish 80:80 --detach nginx

Listing all the running containers

docker container ls

Listing all the running/not running containers

docker container ls -a

 

Docker RUN vs. START

docker container run always starts a new container

docker container start starts an existing stopped one

To give a name to containers

docker container run --publish 80:80 --detach --name <container-name> nginx

If we are running container in detached mode, this is how you can check the logs generated by your container while running nginx server

docker container logs <container-name>

We can also run commands inside docker a below

docker container top <container-name>

docker container ls <container-name>

Once you are done with testing our containers, we can remove them all by running below command

docker container rm <container-id> <2nd-container-id>

The above command will give you an error if you're trying to delete the running containers. To delete running container use -f attribute.

To pass Environment variables to containers use --env or -e