0% found this document useful (0 votes)
5 views4 pages

Docker SpringBoot Interview Guide

The document provides a comprehensive guide on using Docker with Spring Boot, covering Docker basics, common commands, Dockerfile examples, Docker Compose, volumes, networks, best practices, and specific steps for dockerizing a Spring Boot project. It includes practical examples such as creating Dockerfiles, building images, and running containers, as well as a sample Docker Compose configuration for integrating Spring Boot with MySQL. This guide serves as a valuable resource for interview preparation on Docker and Spring Boot topics.

Uploaded by

sxqjvsjng4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

Docker SpringBoot Interview Guide

The document provides a comprehensive guide on using Docker with Spring Boot, covering Docker basics, common commands, Dockerfile examples, Docker Compose, volumes, networks, best practices, and specific steps for dockerizing a Spring Boot project. It includes practical examples such as creating Dockerfiles, building images, and running containers, as well as a sample Docker Compose configuration for integrating Spring Boot with MySQL. This guide serves as a valuable resource for interview preparation on Docker and Spring Boot topics.

Uploaded by

sxqjvsjng4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Docker + Spring Boot Interview Guide

1. Docker Basics

Docker is a platform to package, distribute, and run applications in lightweight containers.

- Image: Blueprint of the container.

- Container: Instance of an image.

- Dockerfile: Script that defines how to build the image.

- Docker Hub: Public registry of Docker images.

2. Common Docker Commands

- docker --version : Check Docker version

- docker ps : List running containers

- docker ps -a : List all containers

- docker start/stop/restart ID : Manage container lifecycle

- docker run -d -p 8080:80 --name mycontainer nginx : Run container in background

- docker rm / rmi ID : Remove container/image

- docker build -t name:tag . : Build image from Dockerfile

- docker exec -it ID /bin/bash : Access running container shell

3. Dockerfile Example

FROM ubuntu

WORKDIR /app

COPY . .

RUN apt-get update

CMD ["node", "app.js"]

EXPOSE 3000
Docker + Spring Boot Interview Guide

4. Docker Compose

A tool for defining and running multi-container Docker apps.

docker-compose.yml example:

version: '3'

services:

web:

image: nginx

ports:

- "8080:80"

db:

image: mysql

environment:

MYSQL_ROOT_PASSWORD: example

Commands:

- docker-compose up

- docker-compose down

5. Docker Volumes and Networks

- docker volume create myvol

- docker run -v myvol:/data image

- docker network create mynet

- docker network ls
Docker + Spring Boot Interview Guide

6. Docker Best Practices

- Use small base images (e.g., Alpine)

- One process per container

- Use .dockerignore

- Tag images (e.g., myapp:1.0.1)

7. Dockerizing a Spring Boot Project

Steps:

1. Build your project:

mvn clean install

2. Create Dockerfile:

FROM openjdk:17-jdk-slim

WORKDIR /app

COPY target/myapp.jar app.jar

ENTRYPOINT ["java", "-jar", "app.jar"]

3. Build Docker Image:

docker build -t my-springboot-app .

4. Run Docker Container:

docker run -d -p 8080:8080 --name springapp my-springboot-app

5. Test: http://localhost:8080
Docker + Spring Boot Interview Guide

8. Spring Boot + MySQL using Docker Compose

docker-compose.yml:

version: '3'

services:

app:

build: .

ports:

- "8080:8080"

depends_on:

- db

db:

image: mysql:8

environment:

MYSQL_ROOT_PASSWORD: root

MYSQL_DATABASE: mydb

Command:

docker-compose up --build

You might also like