Junior — Middle
How can you create a containerized application using Docker to prepare its image for deployment?
sobes.tech AI
Answer from AI
To create a containerized application using Docker and prepare an image for deployment, you need to:
- Write a Dockerfile — a text file with instructions for building the image.
- In the Dockerfile, specify the base image, copy the source code, install dependencies, and set the startup command.
- Build the image with the command:
docker build -t image_name .
- Test the image by running a container:
docker run -p 8080:8080 image_name
Example Dockerfile for a Java application:
FROM openjdk:17-jdk-slim
COPY target/app.jar /app.jar
ENTRYPOINT ["java", "-jar", "/app.jar"]
Here, we use the official OpenJDK image, copy the built jar file, and set the startup command.
After building the image, you can upload it to Docker Registry and deploy it on a server or in the cloud.