Build Docker environment (Linux 8) and start Apache HTTP Server container

Purpose

Build a Docker operating environment on AWS EC2, create an Apache HTTP Server container, and run it. Understand the basic operation of containers. (Pattern to operate after logging in to the container and pattern to use Docker File are implemented.)

Environmental condition

--Docker server - EC2:t2.micro - OS:Red Hat Enterprise Linux 8 (HVM), SSD Volume Type --Disk: General-purpose SSD (GP2) 10GB

The security group settings are nice.

Construction procedure

Follow the procedure below.

  1. Build an operating environment for Docker on EC2.
  2. Download the CentOS image from Docker Hub.
  3. Start the downloaded image, log in to the container, and run Apache HTTP Server.
  4. Operation check.
  5. Create a Apache HTTP Server container using Docker File and run it.
  6. Operation check.

1. Build an operating environment for Docker on EC2.

Log in to the Docker server with ec2-user

##Switch to root user
sudo su - 
##Various library updates
dnf -y update
##Check the repository
dnf repolist

repo id repo name rhel-8-appstream-rhui-rpms Red Hat Enterprise Linux 8 for x86_64 - AppStream from RHUI (RPMs) rhel-8-baseos-rhui-rpms Red Hat Enterprise Linux 8 for x86_64 - BaseOS from RHUI (RPMs) rhui-client-config-server-8 Red Hat Update Infrastructure 3 Client Configuration Server 8

##Add Docker repository
dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

Adding repo from: https://download.docker.com/linux/centos/docker-ce.repo

##Confirm that the repository has been added
dnf repolist

repo id repo name docker-ce-stable Docker CE Stable - x86_64 rhel-8-appstream-rhui-rpms Red Hat Enterprise Linux 8 for x86_64 - AppStream from RHUI (RPMs) rhel-8-baseos-rhui-rpms Red Hat Enterprise Linux 8 for x86_64 - BaseOS from RHUI (RPMs) rhui-client-config-server-8 Red Hat Update Infrastructure 3 Client Configuration Server 8

##Check the existence of the Docker library to be installed
dnf info docker-ce

Last metadata expiration check: 0:00:54 ago on Tue 29 Dec 2020 12:15:56 AM UTC. Available Packages Name : docker-ce Epoch : 3 Version : 20.10.1 Release : 3.el8 Architecture : x86_64 Size : 27 M Source : docker-ce-20.10.1-3.el8.src.rpm Repository : docker-ce-stable Summary : The open-source application container engine URL : https://www.docker.com License : ASL 2.0 Description : Docker is a product for you to build, ship and run any application as a : lightweight container. : : Docker containers are both hardware-agnostic and platform-agnostic. This means : they can run anywhere, from your laptop to the largest cloud compute instance and : everything in between - and they don't require you to use a particular : language, framework or packaging system. That makes them great building blocks : for deploying and scaling web apps, databases, and backend services without : depending on a particular stack or provider.

dnf info docker-ce-cli

Last metadata expiration check: 0:01:00 ago on Tue 29 Dec 2020 12:15:56 AM UTC. Available Packages Name : docker-ce-cli Epoch : 1 Version : 20.10.1 Release : 3.el8 Architecture : x86_64 Size : 33 M Source : docker-ce-cli-20.10.1-3.el8.src.rpm Repository : docker-ce-stable Summary : The open-source application container engine URL : https://www.docker.com License : ASL 2.0 Description : Docker is is a product for you to build, ship and run any application as a : lightweight container. : : Docker containers are both hardware-agnostic and platform-agnostic. This means : they can run anywhere, from your laptop to the largest cloud compute instance and : everything in between - and they don't require you to use a particular : language, framework or packaging system. That makes them great building blocks : for deploying and scaling web apps, databases, and backend services without : depending on a particular stack or provider.

dnf info containerd.io

Last metadata expiration check: 0:01:04 ago on Tue 29 Dec 2020 12:15:56 AM UTC. Available Packages Name : containerd.io Version : 1.4.3 Release : 3.1.el8 Architecture : x86_64 Size : 33 M Source : containerd.io-1.4.3-3.1.el8.src.rpm Repository : docker-ce-stable Summary : An industry-standard container runtime URL : https://containerd.io License : ASL 2.0 Description : containerd is an industry-standard container runtime with an emphasis on : simplicity, robustness and portability. It is available as a daemon for Linux : and Windows, which can manage the complete container lifecycle of its host : system: image transfer and storage, container execution and supervision, : low-level storage and network attachments, etc.

##Install Docker library
dnf -y install docker-ce docker-ce-cli containerd.io
##Docker service registration
systemctl enable docker

Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.

##Start Docker
systemctl start docker
##Docker startup confirmation
systemctl status docker

● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled) Active: active (running) since Tue 2020-12-29 00:19:07 UTC; 9s ago Docs: https://docs.docker.com Main PID: 58369 (dockerd) Tasks: 8 Memory: 59.2M CGroup: /system.slice/docker.service └─58369 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

##Docker version check
docker --version

Docker version 20.10.1, build 831ebea

##Run Hello World
docker run hello-world

`Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 0e03bdcc26d7: Pull complete Digest: sha256:1a523af650137b8accdaed439c17d684df61ee4d74feac151b5b337bd29e7eec Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps:

  1. The Docker client contacted the Docker daemon.
  2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64)
  3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading.
  4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/get-started/ `

2. Download the CentOS image from Docker Hub.

##Check Docker image
docker images

REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest bf756fb1ae65 12 months ago 13.3kB

##Download CentOS 8 image from Docker Hub
docker pull centos:centos8

centos8: Pulling from library/centos 7a0437f04f83: Pull complete Digest: sha256:5528e8b1b1719d34604c87e11dcd1c0a20bedf46e83b5632cdeac91b8c04efc1 Status: Downloaded newer image for centos:centos8 docker.io/library/centos:centos8

##That the Docker image has been added
docker images

REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest bf756fb1ae65 12 months ago 13.3kB centos centos8 300e315adb2f 3 weeks ago 209MB

3. Start the downloaded image, log in to the container, and run Apache HTTP Server.

##Start CentOS container (Map 8080 port of OS to 80 port of container)
docker run --detach --name test --privileged --publish=8080:80 centos:centos8 /sbin/init

b25e9ef1d672f5e802eaa03983457c9730c9a5805a7d1abddb4ad9056ec15a01

##Make sure port 8080 is listening on a Docker container
netstat -nap | grep 8080

tcp6 0 0 :::8080 :::* LISTEN 58798/docker-proxy

##Check the process status of the started container
docker ps -a

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b25e9ef1d672 centos:centos8 "/sbin/init" 2 minutes ago Up 2 minutes 0.0.0.0:8080->80/tcp test 28a9e2902746 hello-world "/hello" 9 minutes ago Exited (0) 9 minutes ago nervous_wilbur

Log in to the container
# docker exec -it test bash

Below, it is carried out while logged in to the container

##OS check of container
cat /etc/os-release 

NAME="CentOS Linux" VERSION="8" ID="centos" ID_LIKE="rhel fedora" VERSION_ID="8" PLATFORM_ID="platform:el8" PRETTY_NAME="CentOS Linux 8" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:centos:centos:8" HOME_URL="https://centos.org/" BUG_REPORT_URL="https://bugs.centos.org/" CENTOS_MANTISBT_PROJECT="CentOS-8" CENTOS_MANTISBT_PROJECT_VERSION="8"

##Check the kernel of the container
uname -a

Linux b25e9ef1d672 4.18.0-240.1.1.el8_3.x86_64 #1 SMP Fri Oct 16 13:36:46 EDT 2020 x86_64 x86_64 x86_64 GNU/Linux

##Install Apache HTTP Server in a container
dnf install -y httpd
##Check the version of installed Apache HTTP Server
httpd -v

Server version: Apache/2.4.37 (centos) Server built: Nov 4 2020 03:20:37

##Apache HTTP Server service registration
systemctl enable httpd

Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.

##Start Apache HTTP Server
systemctl start httpd
##Check the startup status of Apache HTTP Server
systemctl status httpd
##index.Creating html
vi /var/www/html/index.html
cat /var/www/html/index.html 
<html>
<body>
Test Container HTML File
</body>
</html>

4. Operation check.

##Checking the operation of Apache HTTP Server in the container
curl -i http://localhost/

`HTTP/1.1 200 OK Date: Tue, 29 Dec 2020 00:38:51 GMT Server: Apache/2.4.37 (centos) Last-Modified: Tue, 29 Dec 2020 00:37:43 GMT ETag: "37-5b78f99486ca0" Accept-Ranges: bytes Content-Length: 55 Content-Type: text/html; charset=UTF-8

Test Container HTML File `

Exit from the container with control + d (because it's a Mac)

Access the URL below from your PC browser and Confirm that "This page is not working ec2-13-114-50-13.ap-northeast-1.compute.amazonaws.com did not send data. ERR_EMPTY_RESPONSE" is displayed. http: // : 80

Access the URL below from your PC browser and Confirm that Test Container HTML File is displayed http: // : 8080

##Stop container
docker stop b25e9ef1d672

b25e9ef1d672

##Delete container process
docker rm b25e9ef1d672

b25e9ef1d672

5. Create a Apache HTTP Server container using Docker File and run it.

##Creating a directory for Docker File
mkdir -p docker/httpd
cd docker/httpd/
##Create Docker File (Install Apache HTTP Server and start httpd process when container starts. Index..Also create html. )
vi DockerFile
cat Dockerfile 
# setting base image
FROM centos:centos8
# Auther
MAINTAINER MARTOON
# install Apache httpd server
RUN dnf install -y httpd
# create index.html
RUN echo "sample httpd container" > /var/www/html/index.html
# enable httpd
RUN systemctl enable httpd
# start httpd
CMD systemctl start httpd
##Build Docker Image from Docker File
docker build -t sample_httpd:0.1 .
##Confirmation of the existence of the built container image
docker images

REPOSITORY TAG IMAGE ID CREATED SIZE sample_httpd 0.1 6892219088b3 24 seconds ago 250MB centos centos8 300e315adb2f 3 weeks ago 209MB hello-world latest bf756fb1ae65 12 months ago 13.3kB

##Launch the built container image
docker run --detach --name sample_httpd --privileged --publish=8080:80 sample_httpd:0.1 /sbin/init

d7bd77d61494b97fa00c5664aed59d9080c0b1d210581b2c3a7732f1ab47c94b

6. Operation check.

Access the URL below from your PC browser and Confirm that "This page is not working ec2-13-114-50-13.ap-northeast-1.compute.amazonaws.com did not send data. ERR_EMPTY_RESPONSE" is displayed. http: // : 80

Access the URL below from your PC browser and Confirm that sample httpd container is displayed http: // : 8080

##Check the Docker process
docker ps -a

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d7bd77d61494 sample_httpd:0.1 "/sbin/init" About a minute ago Up About a minute 0.0.0.0:8080->80/tcp sample_httpd

##Stop the started container
docker stop d7bd77d61494

d7bd77d61494

##Delete the started container
docker rm d7bd77d61494

d7bd77d61494

##Checking the container image
docker images

REPOSITORY TAG IMAGE ID CREATED SIZE sample_httpd 0.1 8d1a1edebfdf 3 minutes ago 250MB centos centos8 300e315adb2f 3 weeks ago 209MB hello-world latest bf756fb1ae65 12 months ago 13.3kB

##Delete the built container image
docker rmi 8d1a1edebfdf
##Confirm that the container image has been deleted
docker images

REPOSITORY TAG IMAGE ID CREATED SIZE centos centos8 300e315adb2f 3 weeks ago 209MB hello-world latest bf756fb1ae65 12 months ago 13.3kB

Recommended Posts

Build Docker environment (Linux 8) and start Apache HTTP Server container
Build a CentOS Linux 8 environment with Docker and start Apache HTTP Server
Build Apache HTTP Server and Wildfly on Oracle Linux 8
[Linux] Build a jenkins environment with Docker
[Linux] Build a Docker environment with Amazon Linux 2
Build PyPy and Python execution environment with Docker
Flutter in Docker-How to build and use a Flutter development environment inside a Docker container
Source compile Apache2.4 (httpd 2.4.43) + PHP7.4 on Linux and build a Web server ―― 1. Apache introduction
Source compile Apache2.4 (httpd 2.4.43) + PHP7.4 on Linux and build a Web server --2 PHP introduction
Build a Docker container and save png from altair
[Linux] Create a self-signed certificate with Docker and apache
Install LAMP on Amazon Linux 2 and build a WordPress environment.
Build a Docker environment that can use PyTorch and JupyterLab
[Django] Build a Django container (Docker) development environment quickly with PyCharm
Build a Python environment and transfer data to the server
Build GPU environment with GCP and kaggle official image (docker)
Build a LAMP environment with Vagrant (Linux + Apache + MySQL + PHP)
Build and try an OpenCV & Python environment in minutes using Docker
[DynamoDB] [Docker] Build a development environment for DynamoDB and Django with docker-compose
Linux Web server construction (Ubuntu & Apache)
Build a go environment using Docker
(Windows10) Install Linux environment and gnuplot.
Build Mysql + Python environment with docker
Build PyPy execution environment with Docker
[Linux] Docker environment construction on Redhat
Build a Postfix mail server, start Python code triggered by mail reception, and post mail to Slack (local environment)
Start a web server using Bottle and Flask (I also tried using Apache)
Build Linux on a Windows environment. Steps to install Laradock and migrate
Build a lightweight server in Python and listen for Scratch 2 HTTP extensions
How to build my own Linux server
[UE4] Build DedicatedServer on Windows and Linux
Build Jupyter Lab (Python) environment with Docker
Build Python3 and OpenCV environment on Ubuntu 18.04
Build an NFS server on Arch Linux
Build a simple WebDAV server on Linux
Build CGI Server running on Python 3 on Docker
Build an LNPP environment on Amazon Linux 2
Install and Configure TigerVNC server on Linux
Build a Samba server on Arch Linux
Build NGINX + NGINX Unit + MySQL environment with Docker
Source compile Apache2.4 + PHP7.4 with Raspberry Pi and build a Web server --2 PHP introduction
Build a Python + bottle + MySQL environment with Docker on RaspberryPi3! [Trial and error]
Source compile Apache2.4 + PHP7.4 with Raspberry Pi and build a Web server ―― 1. Apache introduction
Create a Django project and application in a Python virtual environment and start the server
How to run a Django application on a Docker container (development and production environment)