Learn how to spin up docker container
Tags: programming, docker, beginners, tutorial
Published: 2022-09-17 11:19:47

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](https://hub.docker.com/search?q=&type=image).
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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z5c0orugiwlyq9prce07.png)
In the docker desktop you can see our new container created.

![Docker desktop](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8il6kwlwiqattz27qx6a.png)

Now we can access our container myNginx on port 8080.

![Accessing localhost on browser](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ro3ad7if9l084g7z06ge.png)

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

`docker start `

![Docker Start](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gca9u3xmneek0a6xoi1c.png)

![Docker status](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p6kn8e0d6xhngnrxxe4y.png)

### 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w0ea7znqjfnu5l3fduvg.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6zkhqsmjqngbbg126xtz.png)
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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uel82qqguzh66ngk2pkf.png)

And our docker ps command shows the status as Exited

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sbdsjr5nyqreo65c9jfc.png)

### Docker rm
Docker rm command will remove the specific container permanently

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o7mf8u9wwrmzn4dinwqq.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tsj18ypgtoy15sfk70so.png)

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