How to Install Docker, Create - Container, Start Container, Stop Container, Delete Container in Ubuntu Server
Tags: devops, docker
Published: 2023-11-05 15:29:36

In this lab tutorial I tried to show how to Install Docker, Create - Container, Start Container, Stop Container, Delete Container  in Ubuntu Server. Follow the steps :


**Step 1:** For Docker installation, at first you have to write these two commands. I am using `ubuntu server 22.04.3 LTS`.

	

```
sudo apt install docker.io
```
	

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

---

```
sudo snap install docker
```

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



---



**Step 2:** Check if Docker is installed or not. For checking write this command

	

```
which docker
```

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

---


**Step 3:** To see all images present in your local machine. Write this command. What do you see? Nothing ? Yes, you are right. Initially there is no image because you did not create any image.

	

```
sudo docker images
```

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

---


**Step 4:** To find out images in docker hub. Here I want to search for a ubuntu machine. Just write this command to find out all Ubuntu images or other packages. Remember you should write what name is assigned by the docker hub. Here “ubuntu” is named as ubuntu image. You can download this ubuntu image by this command. Any images you can download by this command.

	→ Usage: sudo docker pull <image name>
	

```
sudo docker pull ubuntu 
```

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

---


**Step 5:** By this command you can create a container with an image,pull the image, run the image inside the container, and get inside the container with interactive bash shell. Here, `[run = run the the image inside the container, -it = interactive terminal or bash shell, --name = name of the container (“mycontainer”), ubuntu = image name,  /bin/bash = default directory you should add ]`

	

```
sudo docker run -it --name mycontainer ubuntu /bin/bash
```

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

---

**Step 6:** If you want to come out from the container you can write this command.

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

---



**Step 7:** Now you can see the docker images by this command. Here you can see the ubuntu image is created.


```
sudo docker images
```

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


---

**Step 8:** To check status if the docker service starts or not by this command. You can see the service has already started. After checking the status type “q” for quit.

	
```
Service docker status
```

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

---




**Step 9:**  To see only running containers by this command. Here [p = process, s = start] . What do you see? Nothing ? Yes, there is no running container yet.

```
sudo docker ps
```

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

---

**Step 10:** Now let's run the container and check running status by this command. You can see the container status is “Up” that means the container is running.

	→ Usage: sudo docker start <container name>

```
	sudo docker start mycontainer
	sudo docker ps
```
 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3eyemien38twiz2e5ww9.png)


---


**Step 11:** You can go inside the container by this command. If you do “ls” then you will see the Linux file system inside the container.

	→ Usage: sudo attach <container name>
	

```
sudo attach mycontainer
```

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

---

**Step 12:**  Two useful commands. [p = process, s = start, -a = all].

```
sudo docker ps
```
  {It is used for show only running containers}

```
sudo docker ps -a
```
  {It is used for show running and also stopped containers at the same time}

---

**Step 13:**  Stop container

	→ Usage: sudo docker stop <container name>
	

```
sudo docker stop mycontainer
```

---

**Step 14:** Delete the container. [rm = remove].

	→ Usage: sudo docker rm <container name>
	

```
sudo docker rm mycontainer
```


---

---

Related keywords: 
Docker installation Ubuntu;
Install Docker on Ubuntu;
Docker CE installation guide for Ubuntu;
How to set up Docker on Ubuntu server;
Getting started with Docker on Ubuntu;
Create Docker container on Ubuntu;
Docker run command Ubuntu example;
Docker container tutorial for Ubuntu;
Step-by-step guide to create Docker container on Ubuntu;
Running applications in Docker on Ubuntu server;

Kamrul devops; kamrul-hasan-devops; kamrul-hasan-aws-solution-architect; kamrul-devops; kamrul-cloud; kamrul-hasan-devops; kamrul-devops-engineer; devops-engineer; kamrul-hasan-devops-engineer;