Docker series (Part 1): Install Docker in Ubuntu
Tags: ubuntu, docker
Published: 2022-05-19 08:12:00

You can manually download Docker for your Ubuntu but we will use a trick here. 
First go to https://get.docker.com/
Copy the command

```
curl -fsSL https://get.docker.com -o get-docker.sh
```
to your Terminal.

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

```
sh get-docker.sh
```
We followed this because, this commands automatically finds out all demands for your OS and does all of that.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ni2fvb19bbas0o97utv1.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wwrtsscf9drqi1v490pq.png)

Now, add your user account with the Docker Group

```
sudo groupadd docker

sudo usermod -aG docker $USER

```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xnckebrc3rp34r84lyif.png)
NOw, let's check if docker works in our system
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uw26d2mz0nbs8n9c4meu.png)

Download Docker Compose

```
DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}

 mkdir -p $DOCKER_CONFIG/cli-plugins

 curl -SL https://github.com/docker/compose/releases/download/v2.5.1/docker-compose-linux-x86_64 -o $DOCKER_CONFIG/cli-plugins/docker-compose

```

Surely instead of v2.5.1, you need to go to [GitHub Page](https://github.com/docker/compose/releases/) and choose the latest release number.
Also, add this line

```
chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose
```

Let's check the docker compose version now

```
docker compose version
```


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

If you face any problem, go to root using

```
sudo -i
```

and follow all of the steps to install it.


Now lets run a container in Ubuntu

```
sudo docker container run --publish 80:80 nginx

```

Now , go to terminal and type `localhost`. You will see this.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gqazrven7wjpubegapfb.png)
Press Ctrl+C to exit.

Let's now create a new container

```
sudo docker container run --publish 80:80 --detach nginx
```
This command also shows the container ID.

let's see the list of containers

```
sudo docker container ls
```
 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6bh27bq94dvn18p3br78.png)
Now  lets stop the container

```
sudo docker container stop <1st few numbers of container ID>
```


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0q50srf0eq4iag2818ho.png)
Now, we have no containers left . Check this using

```
sudo docker container ls
```


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

Is it so???

Let's run 

```
sudo docker container ls -a
```


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

Because

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vgkw3b4nv2yc8fsvib58.png)
We have used the command `docker container run` twice . Each time we run that command, it creates a container from the image (nginx) .
Also, you can see Container name which we never set but docker did by itself. Now, lets set that and create a new container 

```
docker container run --publish 80:80 --detach --name  mitulhost nginx
``` 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gsiwc1qmwkn5k9i2hc4y.png)
Checkout the container list

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

Now, lets go to the browser and type `localhost` and refresh it to generate some logs . Then go to the terminal and them type

```
sudo docker container logs mitulhost
```
  

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

I have refreshed my Mozilla browser 4 times and thus you can see 4 lines. That line depends on your refresh.

Now, lets remove our containers. Why I said container, right?
Just type

```
sudo docker container ls -a
```

You will see 3 containers with their unique ID name. We will remove them using those container ID's 1st few digits

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/20ulx772vxq5jsj5uwqi.png)
Look that the the container which had name "mitulhost" can not be removed. Why?

Because it is up and running . So, we can stop it and then run it. But we will do another thing and force it to be removed

```
sudo docker container rm -f <1st few digits of the container id>
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8bsl3go6u58bprs3feg9.png)
  
Now, check if any container is left or not?

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

Done then  

<img src="https://c.tenor.com/Tvd3VKwtse0AAAAC/cat-cute.gif">