Skip to content

Instantly share code, notes, and snippets.

@mradzinski
Last active August 7, 2019 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mradzinski/4967a4e3bdac27e2db762753a9325e64 to your computer and use it in GitHub Desktop.
Save mradzinski/4967a4e3bdac27e2db762753a9325e64 to your computer and use it in GitHub Desktop.
Deploying a Vertx fat-jar into EC2 (Ubuntu)

Deploying a Vertx fat-jar into EC2 (Ubuntu)

1. Install JDK

  1. sudo apt-get update

  2. Check if java is installed by running java

  3. If java isn't installed: sudo apt install default-jdk

2. Install Docker

  1. sudo curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh

  2. sudo systemctl enable docker

  3. docker —version (Optional to verify installation)

3. Install Docker Compose

  1. sudo curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && sudo chmod +x /usr/local/bin/docker-compose
  2. docker-compose --version (Optional to verify installation)

4. Copy fat-jar into EC2 instance:

  1. From a separate local bash instance run: scp -i "your_pem.pem" /your/fat/jar/path/file-shadow.tar ubuntu@ec2-xx-xx-xx.compute-1.amazonaws.com:~/shadow.tar (pay attention is a tar file)
  2. Now get back to your server bash instance and run : tar -xvf ./shadow.tar
  3. Now navigate inside the created folder, and into lib which is where your fat .jar is located at.

5. Build your Docker image

  1. nano Dockerfile (at the location of your fat jar) add the following content, and save:
FROM openjdk:latest
COPY ./your_fat_jar_name.jar fat.jar
EXPOSE your_vertx_server_port
ENTRYPOINT java -jar fat.jar
  1. sudo docker build -t choose_your_docker_image_name . (pay attention to the . at the end)

6. Create your Docker Compose configuration file

  1. nano docker-compose.yml (at the location of your fat jar) add the following content, and save:
version: "3.3"
services:
  choose_your_service_name:
    restart: always
    image: your_docker_image_name
    container_name: choose_your_container_name
    ports:
      - "choose_exposed_port_normally_80:your_vertx_server_port"

7. Time to run your Verticle

  1. sudo docker-compose up -d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment