Skip to content

Instantly share code, notes, and snippets.

@jclaret
Last active October 1, 2021 00:27
Show Gist options
  • Save jclaret/7864ad5ca55e6f008beacea2d4fd7e29 to your computer and use it in GitHub Desktop.
Save jclaret/7864ad5ca55e6f008beacea2d4fd7e29 to your computer and use it in GitHub Desktop.

NOTE: git clone https://github.com/yourgituser/DO180-apps

Creating Containerized Services

podman search rhel

podman pull rhel

podman images

podman run ubi7/ubi:latest echo 'RHEL Image is ready!'

podman run -d rhscl/httpd-24-rhel7:2.4-36.8

podman inspect -l -f "{{.NetworkSettings.IPAddress}}"

curl http://<ip_address>:8080

podman run -it ubi7/ubi:7.7 /bin/bash

podman run -e VAR1=hola -e VAR2=podman rhel7:7.5 printenv VAR1 VAR2

podman run --name mysql-basic
-e MYSQL_USER=user -e MYSQL_PASSWORD=password
-e MYSQL_DATABASE=items -e MYSQL_ROOT_PASSWORD=password
-d rhscl/mysql-57-rhel7:5.7-3.14

podman ps --format "{{.ID}} {{.Image}} {{.Names}}"

podman exec -it mysql-basic /bin/bash

mysql> mysql -uroot
mysql> show databases;
mysql> use items;
mysql> show tables;
mysql> insert into Projects (id, name, code) values (1,'Project1','WinnerWinner');
mysql> select * from Projects;
mysql> exit

podman run -d -p 8080:80 --name httpd-basic redhattraining/httpd-parent:2.4

curl http://localhost:8080

podman exec -it httpd-basic /bin/bash

echo "Winner Winner, Chicken Dinner" > /var/www/html/index.html

curl http://localhost:8080

Creating Containers

podman run rhscl/httpd-24-rhel7

podman ps

podman run --name my-httpd-container rhscl/httpd-24-rhel7

podman run --name my-httpd-container -d rhscl/httpd-24-rhel7

podman run rhscl/httpd-24-rhel7 ls /tmp

podman run -it rhscl/httpd-24-rhel7 /bin/bash

podman exec 11d6e671a611 cat /etc/hostname

podman exec my-httpd-container cat /etc/hostname

podman exec -l cat /etc/hostname

podman ps

podman ps -a

podman inspect my-httpd-container

podman inspect -f '{{ .NetworkSettings.IPAddress }}' my-httpd-container

podman stop my-httpd-container

podman kill my-httpd-container

podman kill -s SIGKILL my-httpd-container

podman restart my-httpd-container

podman rm my-httpd-container

podman rm -a

podman stop -a

podman run --name mysql-db rhscl/mysql-57-rhel7

podman logs mysql-db

podman run --name mysql
-d -e MYSQL_USER=user -e MYSQL_PASSWORD=password
-e MYSQL_DATABASE=items -e MYSQL_ROOT_PASSWORD=password
rhscl/mysql-57-rhel7

podman ps

podman inspect -f '{{ .NetworkSettings.IPAddress }}' mysql

mysql -uuser1 -h 10.99.1.6 -p items

mysql> CREATE TABLE Projects (id int(11) NOT NULL, \
    name varchar(255) DEFAULT NULL, code varchar(255) DEFAULT NULL, \
    PRIMARY KEY (id));
mysql> insert into Projects (id, name, code) values (1,'WinnerWinner','Dinner');
mysql> exit

mysql -uuser1 -h 10.99.1.6 -ppassword items < manage-lifecycle/db.sql

podman run --name mysql-2 -it rhscl/mysql-57-rhel7 /bin/bash

mysql -uroot # Fail

podman ps -a --format="table {{.ID}} {{.Names}} {{.Status}}"

podman exec mysql /bin/bash -c 'mysql -uuser -p -e "select * from items.Projects;"'

Attaching Persistent Storage to Containers

mkdir /var/dbfiles; chown -R 27:27 /var/dbfiles

semanage fcontext -a -t container_file_t '/var/dbfiles(/.*)?'

restorecon -Rv /var/dbfiles

podman run -v /var/dbfiles:/var/lib/mysql rhmap47/mysql

mkdir -pv /var/local/mysql

semanage fcontext -a -t container_file_t '/var/local/mysql(/.*)?'

restorecon -R /var/local/mysql; ls -dZ /var/local/mysql

chown -Rv 27:27 /var/local/mysql

podman pull rhscl/mysql-57-rhel7

podman run --name persist-db \

-d -v /var/local/mysql:/var/lib/mysql/data
-e MYSQL_USER=user1 -e MYSQL_PASSWORD=mypa55
-e MYSQL_DATABASE=items -e MYSQL_ROOT_PASSWORD=r00tpa55
rhscl/mysql-57-rhel7

podman ps --format="table {{.ID}} {{.Names}} {{.Status}}"

ls -l /var/local/mysql

Creating a Custom Apache Container Image

podman login quay.io

podman exec -it official-httpd /bin/bash

echo "Winner Winner, Chicken Dinner" > /var/www/html/winner.html; exit

curl 127.0.0.1:8180/winner.html

podman inspect -f "{{range .Mounts}}{{println .Destination}}{{end}}" official-httpd

podman diff official-httpd

podman stop official-httpd

podman images

source /usr/local/etc/ocp4.config

podman tag do180-custom-httpd quay.io/${RHT_OCP4_QUAY_USER}/do180-custom-httpd:v1.0

podman images

podman push quay.io/${RHT_OCP4_QUAY_USER}/do180-custom-httpd:v1.0

podman pull -q quay.io/${RHT_OCP4_QUAY_USER}/do180-custom-httpd:v1.0

podman run -d --name test-httpd -p 8280:80 ${RHT_OCP4_QUAY_USER}/do180-custom-httpd:v1.0

curl http://localhost:8280/winner.html

podman search docker.io/nginx

podman pull docker.io/nginx:1.17

podman run --name official-nginx -d -p 8080:80 docker.io/nginx:1.17

podman exec -it official-nginx /bin/bash

echo 'Winner Winner' > /usr/share/nginx/html/index.html; exit

curl 127.0.0.1:8080

podman stop official-nginx

podman commit -a 'Your Name' official-nginx do180/mynginx:v1.0-SNAPSHOT

podman images

podman run --name official-nginx-dev -d -p 8080:80 do180/mynginx:v1.0-SNAPSHOT

podman exec -it official-nginx-dev /bin/bash

echo 'Chicken Dinner' > /usr/share/nginx/html/index.html; exit

curl 127.0.0.1:8080

podman stop official-nginx-dev

podman commit -a 'Your Name' official-nginx-dev do180/mynginx:v1.0

podman ps -a --format="{{.ID}} {{.Names}} {{.Status}}"

podman rm official-nginx-dev

podman ps -a --format="{{.ID}} {{.Names}} {{.Status}}"

podman rmi do180/mynginx:v1.0-SNAPSHOT

podman images

podman run -d --name my-nginx -p 8280:80 do180/mynginx:v1.0

curl 127.0.0.1:8280

Creating Custom Container Images

vim labs/dockerfile-review/Dockerfile

FROM ubi7/ubi:7.7

MAINTAINER Your Name <youremail>

ENV PORT 8080

RUN yum install -y httpd && \
    yum clean all

RUN sed -ri -e "/^Listen 80/c\Listen ${PORT}" /etc/httpd/conf/httpd.conf && \
    chown -R apache:apache /etc/httpd/logs/ && \
    chown -R apache:apache /run/httpd/

USER apache

# Expose the custom port that you provided in the ENV var
EXPOSE ${PORT}

# Copy all files under src/ folder to Apache DocumentRoot (/var/www/html)
COPY ./src/ /var/www/html/

# Start Apache in the foreground
CMD ["httpd", "-D", "FOREGROUND"]

podman build -t do180/custom-apache .

podman images

podman run -d --name dockerfile -p 20080:8080 do180/custom-apache

podman ps

curl 127.0.0.1:20080

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment