Using Docker with AWS Elastic Beanstalk

Lab setup data from the Pluralsight course on:

Using Docker with AWS Elastic Beanstalk


The Complete Obsolete Guide to Generative AI (from Manning) is a lighthearted look at programming with AI, as well as a rock-solid resource for getting the most out of these insanely powerful services. Let it be your guide to analyzing massive data sources, summarize pages and pages of text, and scour the live internet.

 


Dockerfile Review

Create a simple index.html file and the following dockerfile:

FROM ubuntu:latest
MAINTAINER D Clinton info@bootstrap-it.com
RUN apt-get update
RUN apt-get install -y apache2
ADD index.html /var/www/html/
CMD /usr/sbin/apache2ctl -D FOREGROUND
EXPOSE 80 
==============================================
nano dockerfile
docker build -t myserver .
docker images
docker run -d myserver
docker ps
docker network inspect bridge
curl 172.17.0.2

Docker Swarm and Microservices

In my setup:
192.168.1.17 is the manager
192.168.1.14 is the node

[on manager server:]
docker swarm init
[on node server:]
docker swarm join \ [...]
[on manager server:]
docker node ls
docker info
docker service create -p 80:80 --name webserver nginx
docker service ls 
docker service ps webserver 
docker service scale webserver=5
docker service ps webserver 
docker network ls
docker network inspect docker_gwbridge
"IPv4Address": "172.18.0.3/16"
curl 172.18.0.3

The Elastic Beanstalk Toolset

From local terminal – make sure Docker Engine, curl, and Python3 are already installed.

curl -O https://bootstrap.pypa.io/get-pip.py
python3 get-pip.py --user
[[alternative: sudo apt install python3-pip]]
pip --version
pip install awsebcli --upgrade --user

eb
mkdir myapp
cd myapp
eb init
eb list

Docker in a Beanstalk World

eb platform show
nano Dockerfile
----------------------
# Use the AWS Elastic Beanstalk Python 3.4 image
FROM amazon/aws-eb-python:3.4.2-onbuild-3.5.1

# Exposes port 8080
EXPOSE 8080

# Install PostgreSQL dependencies
RUN apt-get update && \
apt-get install -y postgresql libpq-dev && \
rm -rf /var/lib/apt/lists/*
----------------------
eb create testenv
Dockerrun.aws.json Version 1

mkdir mysingle
cd mysingle
eb init
nano index.html
nano Dockerrun.aws.json
eb local run
eb create mysingle
eb ssh mysingle
cd /var/app/current
ls
cat Dockerfile
eb status
eb terminate
================
{
"AWSEBDockerrunVersion": "1",
"Image": {
"Name": "httpd",
"Update": "true"
},
"Ports": [
{
"ContainerPort": "80"
}
],
"Volumes": [
{
"HostDirectory": "/var/app/current",
"ContainerDirectory": "/usr/local/apache2/htdocs"
}
],
"Logging": "/var/log/myapp"
}
================
================
Authentication code:
"Authentication": {
"Bucket": "my-bucket",
"Key": "mydockercfg"
},
================
Dockerrun.aws.json Version 2

{
"AWSEBDockerrunVersion": 2,
"volumes": [
{
"name": "php-app",
"host": {
"sourcePath": "/var/app/current/php-app"
}
},
{
"name": "nginx-proxy-conf",
"host": {
"sourcePath": "/var/app/current/proxy/conf.d"
}
}
],
"containerDefinitions": [
{
"name": "php-app",
"image": "php:fpm",
"environment": [
{
"name": "Container",
"value": "PHP"
}
],
"essential": true,
"memory": 128,
"mountPoints": [
{
"sourceVolume": "php-app",
"containerPath": "/var/www/html",
"readOnly": true
}
]
},
{
"name": "nginx-proxy",
"image": "nginx",
"essential": true,
"memory": 128,
"portMappings": [
{
"hostPort": 80,
"containerPort": 80
}
],
"links": [
"php-app"
],
"mountPoints": [
{
"sourceVolume": "php-app",
"containerPath": "/var/www/html",
"readOnly": true
},
{
"sourceVolume": "nginx-proxy-conf",
"containerPath": "/etc/nginx/conf.d",
"readOnly": true
},
{
"sourceVolume": "awseb-logs-nginx-proxy",
"containerPath": "/var/log/nginx"
}
]
}
]
}

Preparing a Beanstalk Environment

docker login
ls -a
cd .docker
ls
cat config.json
cp config.json dockerconfig
nano dockerconfig
[remove outside auths block (including {})]
mv dockerconfig ../
cd ..

pip install --upgrade --user awscli
aws configure
add credentials
aws s3 ls
aws s3 mb s3://mycreds2324
aws s3 cp dockerconfig s3://mycreds2324

auth snippet:
"AWSEBDockerrunVersion": 2,
"authentication": 
"bucket": "mycreds2324",
"key": "dockerconfig
Launch the Multi-container Project

less Dockerrun.aws.json
eb local run 
eb create wordpress-app

eb ssh
sudo gpasswd -a ec2-user docker
sudo docker network inspect bridge

{
"AWSEBDockerrunVersion": 2,
"containerDefinitions": [
{
"name": "mariadb",
"image": "mariadb:latest",
"essential": true,
"memory": 128,
"portMappings": [
{
"hostPort": 3306,
"containerPort": 3306
}
],
"environment": [
{
"name": "MYSQL_ROOT_PASSWORD",
"value": "password"
},
{
"name": "MYSQL_DATABASE",
"value": "wordpress"
}
]
},
{
"name": "wordpress",
"image": "wordpress",
"essential": true,
"memory": 128,
"portMappings": [
{
"hostPort": 80,
"containerPort": 80
}
],
"links": [
"mariadb"
],
"environment": [
{
"name": "MYSQL_ROOT_PASSWORD",
"value": "password"
}
]
}
]
}