From 4b8c2338fbda5dd42bef2e8296675406a42eb010 Mon Sep 17 00:00:00 2001
From: ludo8147 <ludo8147@bht-berlin.de>
Date: Sun, 8 Sep 2024 22:40:47 +0200
Subject: [PATCH] updated build_Images_start_Containers tutorial

---
 .gitignore                                  |   3 +-
 build_images_start_containers/Containerfile |  10 ++
 build_images_start_containers/terminal.log  | 101 +++++++++++---------
 3 files changed, 67 insertions(+), 47 deletions(-)

diff --git a/.gitignore b/.gitignore
index fb16125..b79563c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,4 +5,5 @@ setup.txt
 todos
 Spin_up_a_virtual_machine_locally/webservice
 
-Spin_up_a_virtual_machine_locally/.vagrant
\ No newline at end of file
+Spin_up_a_virtual_machine_locally/.vagrant
+build_images_start_containers/.aws/credentials
diff --git a/build_images_start_containers/Containerfile b/build_images_start_containers/Containerfile
index 9eedc48..9524adc 100644
--- a/build_images_start_containers/Containerfile
+++ b/build_images_start_containers/Containerfile
@@ -1,7 +1,17 @@
 #https://manpages.ubuntu.com/manpages/jammy/man5/containers-dockerfile.5.html
 FROM ubuntu
 
+RUN apt-get update && apt-get install -y \
+    curl \
+    unzip \
+    less \
+    groff \
+    && curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" \
+    && unzip awscliv2.zip \
+    && ./aws/install
+
 COPY ./artifact.bin /bin/webservice
+COPY ./.aws /root/.aws/
 
 ENV HOST 0.0.0.0
 
diff --git a/build_images_start_containers/terminal.log b/build_images_start_containers/terminal.log
index a2417d8..73bc566 100644
--- a/build_images_start_containers/terminal.log
+++ b/build_images_start_containers/terminal.log
@@ -1,25 +1,57 @@
-lucad@lucad:~/Documents/webservice/build_images_start_containers$ podman build --file ./Containerfile --tag webservice:latest ./
-STEP 1/4: FROM ubuntu
-STEP 2/4: COPY ./artifact.bin /bin/webservice
---> Using cache d48b76170004a6bb0965e8905ddfe75671cb706346500b37028210a1e713ce41
---> d48b76170004
-STEP 3/4: ENV HOST 0.0.0.0
---> Using cache 224047d0ec48afdb18cc4e2bd2c4954b5edd0388ed5a6d6557eca2efbb9646d5
---> 224047d0ec48
-STEP 4/4: ENTRYPOINT [ "/bin/webservice" ]
---> Using cache a4f6895e9c9bd6135b6fc2b1e4ba8bc43a54472e1812b3dbc960933d43e9d7cd
-COMMIT webservice:latest
---> a4f6895e9c9b
-Successfully tagged localhost/webservice:latest
-Successfully tagged localhost/my-webservice:1.0.0
-a4f6895e9c9bd6135b6fc2b1e4ba8bc43a54472e1812b3dbc960933d43e9d7cd
-lucad@lucad:~/Documents/webservice/build_images_start_containers$ podman run --publish 8080:3000 --name test webservice:latest
-Error: creating container storage: the container name "test" is already in use by b9fa9a215008866f64125849976eabae6fce83433f09685899a7898733654641. You have to remove that container to be able to reuse that name: that name is already in use, or use --replace to instruct Podman to do so.
-lucad@lucad:~/Documents/webservice/build_images_start_containers$ podman run --publish 8080:3000 --name webserver-container webservice:latest
-2024/09/02 14:53:21 Starting application...
-time=2024-09-02T14:53:21.710Z level=INFO msg="Using ephemeral store"
-2024/09/02 14:53:21 Configuration loaded: &{Version:n/a FontColor: LogLevel:debug Environment:development Host:0.0.0.0 Port:3000 DatabaseHost: DatabasePort:6379 DatabaseName:0 DatabaseUsername: DatabasePassword:}
-time=2024-09-02T14:53:21.710Z level=INFO msg="Starting server on 0.0.0.0:3000"
+lucad@lucad:~/Documents/webservice/build_images_start_containers$ podman build -t aws-cli-container .
+STEP 1/6: FROM ubuntu
+STEP 2/6: RUN apt-get update && apt-get install -y     curl     unzip     less     groff     && curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"     && unzip awscliv2.zip     && ./aws/install
+--> Using cache ce7b11fabc60c4239105c27cd25dd80b4c58c38df1d475027026251a580af71c
+--> ce7b11fabc60
+STEP 3/6: COPY ./artifact.bin /bin/webservice
+--> Using cache 5d9685f8d4876f0f6f107074d244b83ce562dae47da20d2addc781ef30ae0f47
+--> 5d9685f8d487
+STEP 4/6: COPY ./.aws /root/.aws/
+--> Using cache 1c90ead39ab3e13763719ff51e2f11ea90fee79ca1257a4cf50296a0ebb1e81d
+--> 1c90ead39ab3
+STEP 5/6: ENV HOST 0.0.0.0
+--> Using cache 408f4b6a36bf4992b5c7b1f5bb9aff39e5a1264fda64dbf768ff938ca576d0d4
+--> 408f4b6a36bf
+STEP 6/6: ENTRYPOINT [ "/bin/webservice" ]
+--> Using cache 3a2edc6e8670929ed333858fb066804ba5a30730729fd079e60f89f7d9479b67
+COMMIT aws-cli-container
+--> 3a2edc6e8670
+Successfully tagged localhost/aws-cli-container:latest
+3a2edc6e8670929ed333858fb066804ba5a30730729fd079e60f89f7d9479b67
+lucad@lucad:~/Documents/webservice/build_images_start_containers$ podman run -it -d --name aws-cli -v ./.aws:/root/.aws aws-cli-container
+Error: creating container storage: the container name "aws-cli" is already in use by 5af623036260134d44271ee90f389fce2084069e8faf7268ccfbb963ed7be0ca. You have to remove that container to be able to reuse that name: that name is already in use, or use --replace to instruct Podman to do so.
+lucad@lucad:~/Documents/webservice/build_images_start_containers$ podman rm aws-cli
+Error: cannot remove container 5af623036260134d44271ee90f389fce2084069e8faf7268ccfbb963ed7be0ca as it is running - running or paused containers cannot be removed without force: container state improper
+lucad@lucad:~/Documents/webservice/build_images_start_containers$ podman ps
+CONTAINER ID  IMAGE                               COMMAND     CREATED         STATUS         PORTS                   NAMES
+25a11a94dc38  localhost/webservice:latest                     20 minutes ago  Up 20 minutes  0.0.0.0:8080->3000/tcp  test
+5af623036260  localhost/aws-cli-container:latest              5 minutes ago   Up 5 minutes                           aws-cli
+lucad@lucad:~/Documents/webservice/build_images_start_containers$ podman stop aws-cli
+aws-cli
+lucad@lucad:~/Documents/webservice/build_images_start_containers$ podman rm aws-cli
+aws-cli
+lucad@lucad:~/Documents/webservice/build_images_start_containers$ podman run -it -d --name aws-cli -v ./.aws:/root/.aws aws-cli-container
+1d746b3054f4d35b165899be1935bbb018ae0ea6b5fa1f258a5f5efed5caebd3
+lucad@lucad:~/Documents/webservice/build_images_start_containers$ podman exec -it aws-cli /bin/bash
+root@1d746b3054f4:/# aws s3 mb s3://mein-bucket-name
+make_bucket failed: s3://mein-bucket-name An error occurred (InvalidLocationConstraint) when calling the CreateBucket operation: The specified location-constraint is not valid
+root@1d746b3054f4:/# aws s3api create-bucket --bucket mein-bucket-name --region us-east-1
+{
+    "Location": "/mein-bucket-name"
+}
+root@1d746b3054f4:/# exit
+exit
+lucad@lucad:~/Documents/webservice/build_images_start_containers$ podman rm aws-cli
+Error: cannot remove container 1d746b3054f4d35b165899be1935bbb018ae0ea6b5fa1f258a5f5efed5caebd3 as it is running - running or paused containers cannot be removed without force: container state improper
+lucad@lucad:~/Documents/webservice/build_images_start_containers$ podman stop aws-cli
+aws-cli
+lucad@lucad:~/Documents/webservice/build_images_start_containers$ podman rm aws-cli
+aws-cli
+lucad@lucad:~/Documents/webservice/build_images_start_containers$ podman run -it --name aws-cli -v ./.aws:/root/.aws aws-cli-container
+2024/09/08 20:39:46 Starting application...
+2024/09/08 20:39:46 Configuration loaded: &{Version:n/a FontColor: LogLevel:debug Environment:development Host:0.0.0.0 Port:3000 DatabaseHost: DatabasePort:6379 DatabaseName:0 DatabaseUsername: DatabasePassword:}
+time=2024-09-08T20:39:46.970Z level=INFO msg="Using ephemeral store"
+time=2024-09-08T20:39:46.971Z level=INFO msg="Starting server on 0.0.0.0:3000"
 
  ┌───────────────────────────────────────────────────┐ 
  │                    webservice                     │ 
@@ -29,27 +61,4 @@ time=2024-09-02T14:53:21.710Z level=INFO msg="Starting server on 0.0.0.0:3000"
  │                                                   │ 
  │ Handlers ............ 31  Processes ........... 1 │ 
  │ Prefork ....... Disabled  PID ................. 1 │ 
- └───────────────────────────────────────────────────┘ 
-
-^Ctime=2024-09-02T14:53:42.888Z level=INFO msg="HTTP-Server wird ordnungsgemäß heruntergefahren"
-lucad@lucad:~/Documents/webservice/build_images_start_containers$ podman run --publish 8080:3000 -rm --name webserver-container -d webservice:latest
-Error: unknown shorthand flag: 'r' in -rm
-See 'podman run --help'
-lucad@lucad:~/Documents/webservice/build_images_start_containers$ podman run --publish 8080:3000 --rm --name webserver-container -d webservice:latest
-Error: creating container storage: the container name "webserver-container" is already in use by 816358d9051b3892064310cb077261f895c53311c7922216f938d302f4bc1238. You have to remove that container to be able to reuse that name: that name is already in use, or use --replace to instruct Podman to do so.
-lucad@lucad:~/Documents/webservice/build_images_start_containers$ podman run --publish 8080:3000 --rm --name webserver-cont -d webservice:latest
-9531b2801c03ea704dfe946bed58cf67404560cc2b4a3020a6556ac0dcff16d9
-lucad@lucad:~/Documents/webservice/build_images_start_containers$ curl http://localhost:8080
-Hello, World!lucad@lucad:~/Documents/webservice/build_images_start_containers$ podman ps
-CONTAINER ID  IMAGE                        COMMAND     CREATED             STATUS             PORTS                   NAMES
-9531b2801c03  localhost/webservice:latest              About a minute ago  Up About a minute  0.0.0.0:8080->3000/tcp  webserver-cont
-lucad@lucad:~/Documents/webservice/build_images_start_containers$ podman stop 816358d9051b3892064310cb077261f895c53311c7922216f938d302f4bc1238
-816358d9051b3892064310cb077261f895c53311c7922216f938d302f4bc1238
-lucad@lucad:~/Documents/webservice/build_images_start_containers$ podman ps
-CONTAINER ID  IMAGE                        COMMAND     CREATED             STATUS             PORTS                   NAMES
-9531b2801c03  localhost/webservice:latest              About a minute ago  Up About a minute  0.0.0.0:8080->3000/tcp  webserver-cont
-lucad@lucad:~/Documents/webservice/build_images_start_containers$ podman stop 9531b2801c03
-9531b2801c03
-lucad@lucad:~/Documents/webservice/build_images_start_containers$ podman ps
-CONTAINER ID  IMAGE       COMMAND     CREATED     STATUS      PORTS       NAMES
-lucad@lucad:~/Documents/webservice/build_images_start_containers$ 
\ No newline at end of file
+ └───────────────────────────────────────────────────┘ 
\ No newline at end of file
-- 
GitLab