Docker containers are an integral part of the development and management of our DevOps workflow. After this module, you should be comfortable with most tasks required to interact and manage containers along with an understanding of their purpose and basic workings.
For this module, create a new Git repo for your Docker work in Module 11.
It is recommended that you read through each of the official documentation resources listed below and follow some of the links within each resource to help clarify specific tools and their purposes.
Resources and articles:
- What is Docker?
- Official Dockerfile Reference
- Official Docker Engine Docs
- Official Docker Compose Docs
- Official Docker Hub Docs
- Alpine Linux package management
- Docker Self Paced Training
-
Install Docker Toolbox on your local machine. Don't forget to run
/usr/local/bin/docker-machine env defaultandeval $(/usr/local/bin/docker-machine env default)use the default environment. -
Create a Docker Hub account.
-
Login to your Docker Hub account using
docker loginin your terminal window. -
Pull down the
alpine:3.3image from Docker Hub. -
Create a new file called docker-module.txt, and paste the output of
docker imagesinto the file. -
Commit your changes and push up.
-
Run
shinteractively inside of thealpine:3.3container usingdocker run. You should see a prompt showing/ #. -
Using
apk(more info here), install bash while inside of the container. You'll need add bash using the--no-cacheflag. -
Start a bash prompt inside of the container, and paste the current prompt into docker-module.txt.
-
Exit the container.
-
Commit your changes and push up.
-
Attempt to run
bashinside of the container, and paste the output into docker-module.txt.Since containers are immutable, they start in their original state everytime. Since the original state of the container doesn't have
bashinstalled, running the container again restarts the container without bash. This is one of the differences between the way containers and virtual machines handle state. -
Commit your changes and push up.
-
Create a new Dockerfile that extends the
alpine:3.3and installsbash. -
Build a new image with the tag
realpage/alpine-bash:3.3using your new Dockerfile. -
Attempt to run bash inside of the new
realpage/alpine-bash:3.3container, and paste the output into docker-module.txt. -
Exit the container.
-
Commit your changes and push up.
-
Create a new executable file called welcome.sh containing the following:
#!/bin/bash
echo 'Hello, World!'
-
Update the Dockerfile so that welcome.sh is added to
/home/welcome.shwhen the container is built. -
Rebuild the container following the the changes.
-
Run the welcome.sh script within the container using
docker run, and paste the output into docker-module.txt. -
Commit your changes and push up.
-
Update the Dockerfile so that it outputs "Hello, World!" when only running
docker run realpage/alpine-bash:3.3. -
Rebuild the container and run it via
docker run realpage/alpine-bash:3.3. -
Paste the output into docker-module.txt.
-
Commit your changes and push up.
-
Pull down the
dockercloud/hello-worldimage. You can see the Dockerfile for this image [here](docker pull dockercloud/hello-world). -
Run the
dockercloud/hello-worldimage without any arguments or flags.The container continues to run and never exits. If you look at the Dockerfile, you can see that
php-fpmandnginxare running within the container. Sincenginxis run with-g "daemon off;", the process never exits and neither does the container! -
Rerun
docker imagesand paste the output into docker-module.txt. -
Commit your changes and push up.
When you are done, verify you have pushed your changes to GitHub. Please create a tag called v1.0 with a message of "ready for review" in your docker repo. Be sure your tags are pushed to the remote repository and are visible in GitHub.
Create an issue titled Review Module 11 - Docker and @mention your mentor and team leader.