LabWeek4 AssignmentSolution-DockerBasics 1
LabWeek4 AssignmentSolution-DockerBasics 1
Docker Basics
Table of Contents
Exercise 1 Solution
Part 1. Create a custom container image with the ubuntu/apache2 + PHP stack in two layers
Part 2. Push the custom image to your DockerHub
Exercise 2
Part 1. Create a Docker network
Part 2: Deploy the database container
Part 3. Deploy the ToDo app frontend
Part 4: Test the app on local browser
Exercise 1 Solution
Part 1. Create a custom container image with the ubuntu/apache2 + PHP stack in two layers
Pull ubuntu/apache2 image
docker pull ubuntu/apache2
docker images
Run the bare container with Apache2 server. Also, expose the appropriate port of the container to be able to access it
locally.
docker run -itd --name app-dev -p 80:80 ubuntu/apache2
Now, visit http://127.0.0.1:80, you should see the Apache default page similar to below.
docker images
or
docker commit app-dev tsdevopsacp/php-apache
You should be able to see an image uploaded on your DockerHub now under Tags.
Stop and remove the container:
docker stop app-dev
docker rm app-dev
Exercise 2
docker network ls
You should be able to see the web app container running successfully.
Part 4: Test the app on local browser
Connect to the app on your local browser at localhost or 127.0.0.1 at the port you have published the app. (In this case it
is forwarded it to port 80 which is the default HTTP port.)
Note: In case you are getting an SQL error on the todo.php page as shown in the screenshot below, check if your db
container is running successfully with the required configurations and environment variables passed to it.