In this section i will work on understanding how docker works and how to use docker and docker compose to set up applications. the most important part will be to learn how to use docker compose as that is the structure that most commonly used and how to set of networks and how to assign and mount storage.
The command to install docker & docker compose on linux based systems is mentioned below.
sudo snap install docker
To check if docker has been installed correctly, use the code below to test the docker install
sudo docker --version
Output should show docker version and build reference, as shown below
Docker version 24.0.5, build ced0996
To check if docker compose has been installed, use the code below to test the docker compose install
docker compose version
The output should show the version of docker that is running, as shown below
Docker Compose version V2.20.3
Once you have completed the steps above, docker and docker compose will be installed on your linux container / VM
Checking if Docker client and Docker Server are running and have been configured correctly, use the following command
docker version
The output should show the docker client and the docker server version. If both versions show up, this means that docker client and server are running and both have been configured correctly.
To see the current images on your docker instance, you can use the command mentioned below. This command will list out all the images that have been downloaded on your docker instance. As a new installation, there will be no docker images on your docker instance. Therefore no list will be produced.
docker images
To pull a docker image on your docker server, you will use the command below followed by the name of the application and it's version.
docker pull <name of application:application version>
For example, to pull the latest version of unbuntu, the command will be as follows.
docker pull ubuntu:latest
Once you have entered the command above, the latest image of ubuntu will be pulled. You can confirm this by entering the docker images command.
To start containers using the image you have pulled, you will need to use the docker run command. This command will be followed by additional variables which will be explained further.
To run a docker container using the docker run command, you will need to enter the following command in the the format mentioned below.
docker run --name <the name you want to set for the container> -it ubuntu:latest bash
--name (is followed by the name of the container you would need to set the brackets <> are not required in the actual command)
-it (this command tells docker to make the container interactive and to attach the shell to the container's terminal)
ubuntu:latest (this is the image that you are using to create the container)
bash (this tells docker to start a bash shell as the container's main app)
I am still not sure why the bash shell needs to be started and what is exactly does. The booking does not mention this at the moment. In the next pages if it mentions the reasons behind why bash shell needs to be started, I will update this section.