How to Deploy a Java Application in AWS ECS using Terraform

In order to deploy a Java application into AWS ECS (Elastic Container Service) using Terraform, we need to consider a few different things. Step 1 - Java Application Create a file called HelloWorld.java and add the following code to it: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } } We now need to build our class as follows: javac HelloWorld.java Once this is done, we can package our application into a jar file:...

May 23, 2023 · 2 min · 277 words · Andrew

[Solved] Cannot connect to the Docker daemon at unix:/var/run/docker.sock. Is the docker daemon running?

If you get the following error when trying to run a Docker container: Cannot connect to the Docker daemon at unix:/var/run/docker.sock. Is the docker daemon running? Then you can resolve it by running the following: systemctl start docker If this doesn’t work because of a root user issue, then you can do the following first: gpasswd -a $USER docker Additional issues? Issue 1 If you have tried the above, and get this error:...

March 4, 2023 · 1 min · 117 words · Andrew

[Solved] M1 docker preview and keycloak 'image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8)' Issue

If you get the following error when trying to run a Docker container that was built on an M1 mac: M1 docker preview and keycloak 'image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8)' Issue The solution Then you can do simply add the following argument to your docker build command. --platform linux/amd64 Where this goes docker build --platform linux/amd64 -t your_docker_item .

March 3, 2023 · 1 min · 65 words · Andrew

[Solved] jsii.errors.JSIIError: docker exited with status 1

If you get the following error while running AWS CDK: raise JSIIError(resp.error) from JavaScriptError(resp.stack) jsii.errors.JSIIError: docker exited with status 1 Then you can resolve it as follows: How to solve docker exited with status 1 error Make sure that your local Docker client is running. Start docker on the local machine and CDK will be able to make the Docker connections required.

December 8, 2022 · 1 min · 62 words · Andrew

How to Remove Old and Unused Docker Images

If you need to remove any old and unused Docker images, then you can do the following: How to Remove Old and Unused Docker Images Firstly you need to see all the images: docker images You can also use ls to see the Docker Images: docker image ls How to Remove a Single Docker Image The docker rmi command will remove a single Docker image as follows: docker rmi <image_id> You can also use the Docker image names as follows:...

October 15, 2022 · 1 min · 123 words · Andrew

How to Copy Files from Docker Container to Host

If you need to copy files from a Docker Container to the Host, then you can do one of the following: Option 1 – Using docker cp Syntax: docker cp [OPTIONS] CONTAINER: SRC_PATH DEST_PATH Setup the container: # pull the ubuntu image docker pull ubuntu # run the container locally docker run -it -d ubuntu # connect to the container docker exec -it abcde123456 /bin/bash Create a file from the container:...

October 8, 2022 · 1 min · 161 words · Andrew

How to Get the IP Address of a Docker Container

If you need to get the IP Address of a Docker Container, then you can do the following: Option 1 – Connect to the Bridge Network Find out the network setup: docker network ls Create a docker container and assign it to the bridge network: docker run -dt <nginx> Get the information about the container: docker ps Inspect the network: docker network inspect bridge Now you can see the container IP Address....

October 7, 2022 · 1 min · 89 words · Andrew

How to push multiple Dockerfile apps to AWS ECR at the same time

I have a parent directory containing multiple sub-directories. Each of these child directories is a different application and contains a Dockerfile. I want to build and push each image to AWS ECR. The directory looks as follows: ├── apps ├── microservice1 ├── app.js ├── Dockerfile ├── package.json └── readiness.txt ├── frontend ├── Dockerfile ├── index.html ├── package.json ├── server.js ├── microservice2 ├── app.py ├── bootstrap.sh ├── Dockerfile └── requirements.txt Notice there are 3 apps, each with their own Dockerfile, under the parent apps directory....

April 19, 2022 · 1 min · 188 words · Andrew

How to Dockerize a Flask App

If you have a Flask app that you would like packaged in a Docker container, then you can do the following. The steps outlined below will help you create the following directory tree: └── flaskapp ├── Dockerfile ├── app.py └── requirements.txt Step 1 – Create your Flask app In a new directory, create the following files: app.py from flask import Flask app = Flask(__name__) @app.route('/') def hello_geek(): return '<h1>Hello world!</h2>' if __name__ == "__main__": app....

April 14, 2022 · 1 min · 186 words · Andrew

How to Extract the Files in a Docker Image

Ever needed to extract the files in a Docker container? Docker provides the save sub-command. Exporting Docker files into a Tar Archive The examples below use a Docker container called: aoms/hellojava Swap this out with your own container as required. docker save aoms/hellojava > hellojava.tar hellojava.tar now contains a list of files found in the Docker image. Taking it one step further You can make this a bit better by extracting it into a new directory and untarring automatically:...

April 4, 2022 · 1 min · 97 words · Andrew