Exercise Docker Images

Table of Contents

Introduction

This lab will take you through the Docker image creation by "Docker commit"; Let us create two Docker images:

  • One for an Apache server running on Ubuntu

  • Another is for an Nginx server running on CentOS

Exercise 1: Apache Server on Ubuntu

First, pull the Ubuntu image from Docker Hub:

docker pull ubuntu:latest

Then, run a Docker container from the Ubuntu image:

Inside the Docker container, update the system with the latest patches and install Apache:

Start the Apache service and enable it to autostart:

Then, exit the Docker container and commit the changes to a new Docker image:

Finally, run a Docker container from the new image:

Exercise 2: Nginx Server on CentOS

First, pull the CentOS image from Docker Hub:

Then, run a Docker container from the CentOS image:

Inside the Docker container, update the system, install EPEL Release, and install Nginx:

Start the Nginx service and enable it to autostart:

Then, exit the Docker container and commit the changes to a new Docker image:

Finally, run a Docker container from the new image:

Note

The above exercises show how to use service and systemctl commands in Docker commit. However, it's important to note that Docker containers are designed to run one process per container. Therefore, it's not recommended to use systemctl or service to manage services within a container as it goes against this principle. Instead, it's better to run the service directly in the foreground. For Apache and Nginx, this can be done by using the -D FOREGROUND option for Apache and the -g "daemon off;" option for Nginx.

References


Please replace <container_id> with the ID of your Docker container. You can get the ID of the running containers by using the docker ps command.

Last updated