[JAVA] How to update pre-built files in docker container

Introduction

It is the content that investigated how to update the executable file specified as the entry point in the docker container.

Background / Problems

When developing a Web application with Java or kotlin, I think it is common to set up a docker container for development. Below is a part of the Dockerfile for the application layer container.

FROM openjdk:8-jdk-alpine
COPY build/libs/application.jar application.jar
ENTRYPOINT  ["java", "-jar", "application.jar"]

Here's what we're doing in the file: Line 1: Specify base image 2nd line: Copy the built jar file (executable file) from the host side (left) to the container side (right) Line 3: Set up the container startup process (running the jar file you passed above)

The application runs when the command execution process specified at the last entry point is started. During development, the program is rebuilt every time a change is made, but in order to see the change on the actual application, the result of the rebuild must be reflected in the container. A simple method is to stop the created container, delete it, and then rebuild / start the container, but it will take some time (especially rebuilding the container).

Solution

One of the solutions to the above problem is as follows.

solution

  1. Overwrite the old jar file in the container with the new file (application-new.jar) for the running container.
docker cp build/libs/application-new.jar application.jar
  1. Restart the container (container name: app).
docker restart app

This method does not require rebuilding the container, so the container can be updated in a shorter time.

reference

--docker official documentation http://docs.docker.jp/engine/reference/builder.html#from

Recommended Posts

How to update pre-built files in docker container
How to share files with Docker Toolbox
How to use Docker in VSCode DevContainer
[Docker] Copy files from docker container to host
Understand in 5 minutes !! How to use Docker
How to get a heapdump from a Docker container
Copy files from docker container to host (docker cp)
How to install Docker
How Docker works ~ Implement the container in 60 lines
How to start a Docker container with a volume mounted in a batch file
How to input / output IBM mainframe files in Java?
How to delete untagged images in bulk with Docker
How to handle TSV files and CSV files in Ruby
How to Syntax Highlight files like Dockerfile.production in Pycharm
How to launch Swagger UI and Swagger Editor in Docker
How to set Docker nginx
How to update with activerecord-import
How to rollback migration files
[Docker] How to update using a container on Heroku and how to deal with Migrate Error
[Docker context] ~ How to access docker in remote environment from VScode ~
[Docker] How to access the host from inside the container. http://host.docker.internal:
How to use Lombok in Spring
How to find May'n in XPath
Introduction to Linux Container / Docker (Part 1)
How to hide scrollbars in WebView
How to run JUnit in Eclipse
How to iterate infinitely in Ruby
[Rails] How to write in Japanese
How to run Ant in Gradle
[Java] How to update Java on Windows
How to make a Java container
How to master programming in 3 months
How to disassemble Java class files
How to run JavaFX on Docker
How to learn JAVA in 7 days
How to get parameters in Spark
How to install Bootstrap in Ruby
Introduction to Linux Container / Docker (Part 2)
How to decompile java class files
How to use InjectorHolder in OpenAM
[Artifactory] How to use Docker repository
How to introduce jQuery in Rails 6
How to use classes in Java?
How to name variables in Java
How to set Lombok in Eclipse
Pass environment variables to docker container
[Docker] Operation up to container creation # 2
Update MySQL from 5.7 to 8.0 with Docker
How to build CloudStack using Docker
How to start Camunda with Docker
How to concatenate strings in java
How to install Swiper in Rails
How to run a job with docker login in AWS batch
[swift5] How to specify color in hexadecimal
How to implement search functionality in Rails
How to implement date calculation in Java
How to implement Kalman filter in Java
Multilingual Locale in Java How to use Locale
How to use binding.pry for view files
Docker push to GitHub Container Registry (ghcr.io)
How to change app name in rails