All the steps below are based on the prerequisite that Docker is already installed on the machine and Docker is used for both front end and back end development:
a) Create Dockerfile:
The initial step is to create a Dockerfile file using a suitable base image along with all the required steps/commands, like setting environment variables, adding application jar, etc. This creates several layers on the existing base image.
b) Build image:
Once the Dockerfile is ready, we can either use docker command or via a Gradle task to generate a docker image. This image contains all the application dependencies required to run the application in a container.
docker build -t-test/security tool.
c) Run the image:
Once the docker image is built, we can create and start the container using command.
docker run --name rest_tool test/security tool.
d) Start Containers using Compose:
In case we have multiple containers constituting an application like database, messaging queue, etc.; then it is advisable to use docker-compose to run multiple containers simultaneously. It is also useful in the CI pipeline for running the application and performing tests.
docker-compose up
e) Test the Application:
After the containers are up and running, the application is ready for Integration or Acceptance tests to be performed. Ideally, it is integrated into the CI pipeline for determining if the new code changes are affecting the existing flows.
f) Push image:
Typically in a container-based development environment, the deliverable artifact is a docker image. This image needs to be published to an internal Registry like Artifactory so that it can be propagated to next levels like Continuous Delivery and Deployment pipelines.
docker push test/securityTool
g) Production orchestration:
Ideally, organizations need to use orchestration tools like Kubernetes to run the containers in a Pod to perform load balancing, service discovery, etc in a production environment. It also helps in providing scalability and high availability of the application.