Docker containers are an integral part of the development and management of our DevOps workflow. After this module, you should be comfortable with basic 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 2.
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 a Container?
- Official Docker Engine Docs
- Official Dockerfile Reference
- Official Docker Hub Docs
- Alpine Linux package management
- Install Docker Community Edition for Mac on your local machine.
- Create a Docker Hub account if you do not already have one.
- If you do, please pass that along to a team member so we can add you to our organization.
-
Login to your Docker Hub account using
docker login
in your terminal window. -
Pull down the
alpine:latest
image from Docker Hub. -
Create a new file called docker-module.txt, and paste the output of
docker images
into the file. -
Commit your changes and push up.
-
Run
sh
interactively inside of thealpine:latest
container 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-cache
flag. -
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
bash
inside 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
bash
installed, 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:latest
and installsbash
. -
Build a new image with the tag
gentux/alpine-bash:{github-username}
using your new Dockerfile. e.g.gentux/alpine-bash:jlaswell
-
Attempt to run bash inside of the new
gentux/alpine-bash:{github-username}
container, 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.sh
when 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 gentux/alpine-bash:{github-username}
. -
Rebuild the container and run it via
docker run gentux/alpine-bash:{github-username}
. -
Paste the output into docker-module.txt.
-
Commit your changes and push up.
-
Pull down the
dockercloud/hello-world
image. You can see the Dockerfile for this image here. -
Run the
dockercloud/hello-world
image without any arguments or flags.The container continues to run and never exits. If you look at the Dockerfile, you can see that
php-fpm
andnginx
are running within the container. Sincenginx
is run with-g "daemon off;"
, the process never exits and neither does the container! -
Rerun
docker images
and 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 2 - Docker and assign it to @generationtux-helmsmen.