Learn Docker

All the docker commands will be common for Ubuntu, Centos, Windows and Mac IOS

For Installation Click here

How to run containers in Docker?



Find the container you are willing to run using Docker. Such as – Nginx, Redis, Busybox etc. To make things more clear I am showing you an Example – how run apache server using Docker.

First, we need to know the correct name for docker image available.

docker search apache

After running this command you will see all these options. I am using the first image – “httpd”

docker run httpd



Now, Check whether your container is up or not, Below command will list all the running containers

docker ps

OUTPUT

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d951ce6735dd httpd “httpd-foreground” 5 seconds ago Up 3 seconds 80/tcp optimistic_beaver

Using the below commands helps to know the running containers as well as non-running containers

docker ps --all

Note:- If you are trying to access it in the browser it will not because as it is running on a container we need to make a connection between the inside container and outside container.



docker run -p incoming_port:inside_port image_id

Docker run -p 8080:80 d951ce6735dd

How to stop Docker containers and delete?

docker stop container_id (if container do not stop in 10 seconds then it will automatically run kill command.)
docker kill container_id (Stopping the container Forcefully)

To Delete non-running container

docker system prune

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.