DEV Community

Cover image for Learn how to spin up docker container
Ravina Deogadkar
Ravina Deogadkar

Posted on

Learn how to spin up docker container

Hello everyone!, Today we are going to look at step by step process of creating and running a docker container.

Docker is a software platform that lets you build, test and deploy application very quickly. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly Using Docker an application can be easily deployed and scaled in any environment. Docker provides the ability to package and run an application in a loosely isolated environment called a container. Containers are lightweight and contain everything needed to run the application, so you do not need to rely on what is currently installed on the host machine.

Docker uses a client-server architecture. The Docker client talks to the Docker daemon, which does the heavy lifting of building, running, and distributing your Docker containers which may or may not run on same system as client.

Docker create

To create docker container from image we make use of docker create command along with the image.
An image is a read-only template with instructions for creating a Docker container. A container is a runnable instance of an image.

docker create nginx:alpine

This will create container with nginx:alpine image and the container will have some random name assign to it. If the images are not present locally then it will pull it from registry.
We can assign custom name to docker using --name

docker create --name myNginx nginx:alpine

This will create nginx docker container with name myNginx. But to access our container from our computer we need to port forward it to specific port using -p

docker create --name myNginx -p 80:80 -d nginx:alpine

Docker create
In the docker desktop you can see our new container created.

Docker desktop

Now we can access our container myNginx on port 8080.

Accessing localhost on browser

Docker start

Docker start command will start docker container and status of container will change from Created to Running.

docker start

Docker Start

Docker status

Docker ps

Docker ps will list all the running containers and using -a will list all containers created in the machine.

docker ps -a

Docker ps example

You can see our myNginx container created and currently in running state.

Docker images

Docker images command will list down all the images.

docker images -a

Image description
You can see our nginx alpine image the one that we have currently used to create container.

Docker stop

Docker stop command will stop the container and you can see the status turned to Exited state.

Image description

And our docker ps command shows the status as Exited

Image description

Docker rm

Docker rm command will remove the specific container permanently

Image description

You can check using docker ps command that container is removed from machine.

Image description

That's it for today, until next time Happy Coding!..

Top comments (4)

Collapse
 
naucode profile image
Al - Naucode

Great article, keep the good work! Liked and followed! 🚀

Collapse
 
deogadkarravina profile image
Ravina Deogadkar

Thank you ❤️

Collapse
 
posandu profile image
Posandu

Just wondering why are you saying the same on lots of DEV posts?

Collapse
 
sindouk profile image
Sindou Koné

Add to the discussion