Lab 11: Docker

Task 1: Install Docker on Ubuntu

It is recommended that you do not run docker as the root user. If you currently cannot run $ docker with your non-root account, then take the following steps:

If you need to add a user to the docker group that you’re not logged in as, declare that username explicitly using:

$ sudo usermod -aG docker <username>

Task 2: Pull images and run containers

Task 3: Create a custom Docker image

Let’s create a static page website and run it on a Python web server.

Note: There are more effective ways to set up a web server. We use the methods in this lab simply to explore the process of creating a Docker image.

Task 4: Docker inspect and container logs

Docker inspect is used to view low-level information on Docker objects.

Container logging helps developers keep track of patterns, troubleshoot issues, and fix bugs.

Questions to answer

  1. Compare and contrast ENTRYPOINT and CMD in Dockerfile. In what situation would you use each of them?
  2. List five security precautions you will take when building or deploying a Docker resource (image or container).
  3. Show a single line command that will remove all exited Docker containers. Do not use any text filtering editor. Show test results.
  4. Show how you can copy files to a running container without entering the container’s interactive shell.
  5. Create a dockerized web application running on nginx. The web index page index.html should be located on your host machine. The directory containing the index page should be mounted to the container and served from there.

    This means that you should be able to modify the web index page on your host machine without interacting with the container.
    Show all steps taken for the configuration including the test results.

  6. Setup rsyslog on your host machine as a central logging server. Create a Docker container and configure it to forward its log to your central logging server.

    Show steps and test results.

Bonus

  1. Dockerize any open source application of your choice, and host it on Docker hub. Share link to the repository.
  2. Find and fix the problems in the following Dockerfile. There are some issues building the image and also running the container:
    FROM alpine RUN apt-get update && apt-get install -y python3 --no-install-recommends RUN touch index.html RUN echo "<html><h1>Testing web</h1></html>" >> index.html CMD ["python", "-m", "http.server"]

    Show all steps taken to fix it, and a working solution.