How to deploy with Docker

Docker is a platform that provides a virtualisation system on which you can run programs in packages called containers.

Containers are isolated from each other and comprise all required software resources, including the operating system, thus enabling the application to run.

Deploy Docker: Deploy an application with Docker using Docker Image

To deploy an application with Docker, you must first have an image available.

The image, or Docker image, is a read-only artefact that contains a set of instructions for creating a container that can run on the Docker platform. The image provides a particularly convenient method for creating preconfigured application packages and server environments.

The Docker image can be created using a Dockerfile and with the docker build command.

Deploy Docker

We can find the newly created image in the image list with the docker image ls command.

To deploy the application, you will need to have an Ubuntu Server instance with Docker installed. This instance can be on a local or remote virtual machine, or it can be on a dedicated physical machine.

Note that the virtual machine where the deployment will be performed must have access to the created image. To do this, you must copy the image to a docker registry accessible via the internet. There are many services available for this, including Docker Hub, Amazon ECR, and Google Container Registry.

Furthermore, we will need to create an account to get the registry URL and enable it to upload Docker images. At this point, you can load the image using the docker push command:

Deploy Docker

Once this has been done, we access the Ubuntu Docker machine to get the image from the registry:

Deploy Docker

As soon as we have the image, we can launch a container with the docker run command:

Deploy Docker

Deploy Docker: running commands from the container

The -p attribute enables you to map port 80 to make it accessible from the outside. Now, you should be able to run the docker ps command, and you should see the newly launched container in the list.

To execute commands from the container that is running, you can run the docker exec command. By running the bash or sh command, you may use the shell inside the container as follows:

Scaling multiple containers dynamically: container orchestration tools

This is the simplest way to deploy a Docker container. What if we want to run multiple containers and make them interact with each other? What if we want to scale the number of containers dynamically?

To do this, we need a container orchestration tool. There are many, such as Docker Swarm, Kubernetes or Amazon ECS, topics that we will cover in depth in future articles.

We hope that this mini-guide has been of help to you and, above all, that gave you an understanding of how to create an image and deploy a container.

Docker is now an essential tool for anyone involved in web development and server-side programming.

Docker makes it possible to distribute code more quickly. This tool provides a concrete opportunity to standardise the operation of applications by optimising code transfer.

Share: Facebook Twitter Linkedin