Steps

Dockerfiles

Step1 of 3

Base Python Image

Create a Base Image

One of the first things you'll do from a development perspective is create a base image for all of your applications to use. In reality, your platform team typically creates these, and provides them to internal software development teams for usage.

We will create a basic base image for Python applications. Work together in teams of 2-3 people, and create a Dockerfile (/root/resources/python/Dockerfile) with the following specifications:

Base it off a recent Alpine Linux version

Specify a maintainer

Install Python, Pip, and the dev tools

Install virtualenv

Configure the container to always run python3

Once you have your Dockerfile, build the image:

docker image build -t py /root/resources/python/

Then, to verify that it works properly:

docker container run -d -p 8080:5000 py -m http.server 5000

You should be able to access your filesystem on port 8080.

"Docker in Docker"

Running Docker Inside of Docker

Docker in Docker means that you can run a Docker container, which then runs more docker containers. It is pretty cool, and its how Play With Docker works. We will do a "lite" version of this, by creating a Docker container that can run Docker inside of it, but the actual execution is happening on the host.

In teams of 2-3, you will create a Dockerfile (./resources/dind/Dockerfile) that accomplishes the following:

Uses a recent version of Alpine as a base image

Specifies a maintainer via a label

Installs the Docker daemon, client, and all dependencies

Sets the default execution to sh

Once you get there, you will build the Docker image from your Dockerfile. Then, you will run a container, but mount the Docker socket from our host into the container, like so:

The Unix socket located at /var/run/docker.sock is the default means that the Docker client and the Docker daemon use to communicate to each other. By using a bind mount, we are giving our container all of the capabilities the Docker client on our host machine already has.

Once you have your shell opened in the container, run docker container ls -a to verify that it works.

Why is this something we would want to do very sparingly, if ever at all?

NodeJS in Docker

For this final step, we'll create a NodeJS Dockerfile. You can design the Dockerfile however you like. You should create /root/resources/nodejs/Dockerfile, fill it with content, and then build it:

docker image build -t nodejs /root/resources/nodejs

To verify your Dockerfile creates a suitable image, you'll need to create a container from your image, open a shell, and then verify the installation with:

node -v and npm -v

As long as those return values, you're done.

When it comes to creating a Dockerfile, you generally have the knowledge to get your application installed and configured. You'll need to get experience searching for how to install dependencies on your specific platform, which is a skill that most of us already have.

Help

Katacoda offerings an Interactive Learning Environment for Developers. This course uses a command line and a pre-configured sandboxed environment for you to use. Below are useful commands when working with the environment.

cd <directory>

Change directory

ls

List directory

echo 'contents' > <file>

Write contents to a file

cat <file>

Output contents of file

Vim

In the case of certain exercises you will be required to edit files or text. The best approach is with Vim. Vim has two different modes, one for entering commands (Command Mode) and the other for entering text (Insert Mode). You need to switch between these two modes based on what you want to do. The basic commands are: