AWS Amazon Web Services Laravel in Docker on EC2(Part 5) AWS Amazon Web Services Laravel in Docker on EC2(Part 5)

December 3, 2021

aws debian devops laravel

Next in this series, I am setting up a docker container to host a laravel website on AWS.

Following this tutorial

I started with a fresh install of Laravel 8 which is in Part 5 of the repo with this Dockerfile

FROM php:8.0.5
RUN apt-get update -y && apt-get install -y openssl zip unzip git
RUN curl -sS | php -- --install-dir=/usr/local/bin --filename=composer
RUN docker-php-ext-install pdo 
COPY . /app
RUN composer install

CMD php artisan serve --host= --port=8888

BUILD the container

docker build -t laravelDocker .

RUN the container

docker run -p 8888:8888 laravelDocker

STOP the container

The first command shows all the containers, the second stops the container with the id

docker container ls

docker container stop ba0ce2c7575f

visiting http://localhost:8888/ see the laravel frontpage

I am going to set it up on an EC2 server instance, but that doesnt seem the norm with Lightsail, Lambda or ECS seemingly better fits for hosting a container image.

So i have the Debian Instance i setup in part 4 with Terraform, now i am going to manually login via ssh, and setup docker

sudo apt-get update
sudo apt install -y apt-transport-https ca-certificates curl gnupg2 software-properties-common
curl -fsSL | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] $(lsb_release -cs) stable"
sudo apt update
sudo apt install docker-ce

Now i need to add my docker container to docker hub

docker ps # to see the docker images eg. id = 5a6a73bcea26

# docker commit -m "first commit" -a "NAME" laraveldocker allotmentandy/laraveldocker:latest # didnt work :(

docker login

docker tag 5a6a73bcea26 allotmentandy/laraveldocker

docker push allotmentandy/laraveldocker

Et voila! dockerhub / allotmentandy

now i ssh into the EC2 instance

docker pull allotmentandy/laraveldocker
sudo docker run -p 80:80 allotmentandy/laraveldocker

updating the laravel files / dockerfile means a rebuild:

docker build -t allotmentandy/laraveldocker -f Dockerfile  .
docker push allotmentandy/laraveldocker

stopping the container, redoing the pull and running it again. Simples :)

If you would like to contact me you can either use this form on or via Twitter @andylondon