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.
sh get-docker.sh
We followed this because, this commands automatically finds out all demands for your OS and does all of that.
Now, add your user account with the Docker Group
sudo groupadd docker
sudo usermod -aG docker $USER
NOw, let's check if docker works in our system
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 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
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.
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
sudo docker container stop <1st few numbers of container ID>
Now, we have no containers left . Check this using
sudo docker container ls
Is it so???
Let's run
sudo docker container ls -a
Because
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
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
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
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>
Now, check if any container is left or not?
Done then
Top comments (1)
Hey, awesome tutorial!